146
147 @Override
148 int rOp(int v, FBinOp f) {
149 int[] 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 Int256Vector.class,
165 int.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.lane(i);
183 }
184 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
185 } else if (stype == short.class) {
186 short[] a = new short[limit];
284 (species, vector) -> vector.defaultReinterpret(species)
285 );
286 } else if (stype == double.class) {
287 return VectorIntrinsics.reinterpret(
288 Int256Vector.class,
289 int.class, LENGTH,
290 Double256Vector.class,
291 double.class, Double256Vector.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 IntVector reshape(VectorSpecies<Integer> s) {
303 Objects.requireNonNull(s);
304 if (s.bitSize() == 64 && (s.boxType() == Int64Vector.class)) {
305 return VectorIntrinsics.reinterpret(
306 Int256Vector.class,
307 int.class, LENGTH,
308 Int64Vector.class,
309 int.class, Int64Vector.LENGTH,
310 this, s,
311 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
312 );
313 } else if (s.bitSize() == 128 && (s.boxType() == Int128Vector.class)) {
314 return VectorIntrinsics.reinterpret(
315 Int256Vector.class,
316 int.class, LENGTH,
317 Int128Vector.class,
318 int.class, Int128Vector.LENGTH,
319 this, s,
320 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
321 );
322 } else if (s.bitSize() == 256 && (s.boxType() == Int256Vector.class)) {
323 return VectorIntrinsics.reinterpret(
324 Int256Vector.class,
325 int.class, LENGTH,
326 Int256Vector.class,
327 int.class, Int256Vector.LENGTH,
328 this, s,
329 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
330 );
331 } else if (s.bitSize() == 512 && (s.boxType() == Int512Vector.class)) {
332 return VectorIntrinsics.reinterpret(
333 Int256Vector.class,
334 int.class, LENGTH,
335 Int512Vector.class,
336 int.class, Int512Vector.LENGTH,
337 this, s,
338 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
339 );
340 } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
341 && (s.bitSize() % 128 == 0) && (s.boxType() == IntMaxVector.class)) {
342 return VectorIntrinsics.reinterpret(
343 Int256Vector.class,
344 int.class, LENGTH,
345 IntMaxVector.class,
346 int.class, IntMaxVector.LENGTH,
347 this, s,
348 (species, vector) -> (IntVector) 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 IntVector add(int o) {
360 return add((Int256Vector)IntVector.broadcast(SPECIES, o));
361 }
648 @Override
649 @ForceInline
650 public Int256Vector and(Vector<Integer> v, VectorMask<Integer> m) {
651 return blend(and(v), m);
652 }
653
654 @Override
655 @ForceInline
656 public Int256Vector or(Vector<Integer> v, VectorMask<Integer> m) {
657 return blend(or(v), m);
658 }
659
660 @Override
661 @ForceInline
662 public Int256Vector xor(Vector<Integer> v, VectorMask<Integer> m) {
663 return blend(xor(v), m);
664 }
665
666 @Override
667 @ForceInline
668 public Int256Vector shiftL(int s) {
669 return VectorIntrinsics.broadcastInt(
670 VECTOR_OP_LSHIFT, Int256Vector.class, int.class, LENGTH,
671 this, s,
672 (v, i) -> v.uOp((__, a) -> (int) (a << i)));
673 }
674
675 @Override
676 @ForceInline
677 public Int256Vector shiftL(int s, VectorMask<Integer> m) {
678 return blend(shiftL(s), m);
679 }
680
681 @Override
682 @ForceInline
683 public Int256Vector shiftR(int s) {
684 return VectorIntrinsics.broadcastInt(
685 VECTOR_OP_URSHIFT, Int256Vector.class, int.class, LENGTH,
686 this, s,
687 (v, i) -> v.uOp((__, a) -> (int) (a >>> i)));
688 }
689
690 @Override
691 @ForceInline
692 public Int256Vector shiftR(int s, VectorMask<Integer> m) {
693 return blend(shiftR(s), m);
694 }
695
696 @Override
697 @ForceInline
698 public Int256Vector aShiftR(int s) {
699 return VectorIntrinsics.broadcastInt(
700 VECTOR_OP_RSHIFT, Int256Vector.class, int.class, LENGTH,
701 this, s,
702 (v, i) -> v.uOp((__, a) -> (int) (a >> i)));
703 }
704
705 @Override
706 @ForceInline
707 public Int256Vector aShiftR(int s, VectorMask<Integer> m) {
708 return blend(aShiftR(s), m);
709 }
710
711 @Override
712 @ForceInline
713 public Int256Vector shiftL(Vector<Integer> s) {
714 Int256Vector shiftv = (Int256Vector)s;
715 // As per shift specification for Java, mask the shift count.
716 shiftv = shiftv.and(IntVector.broadcast(SPECIES, 0x1f));
717 return VectorIntrinsics.binaryOp(
718 VECTOR_OP_LSHIFT, Int256Vector.class, int.class, LENGTH,
719 this, shiftv,
720 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a << b)));
721 }
722
723 @Override
724 @ForceInline
725 public Int256Vector shiftR(Vector<Integer> s) {
726 Int256Vector shiftv = (Int256Vector)s;
727 // As per shift specification for Java, mask the shift count.
728 shiftv = shiftv.and(IntVector.broadcast(SPECIES, 0x1f));
729 return VectorIntrinsics.binaryOp(
730 VECTOR_OP_URSHIFT, Int256Vector.class, int.class, LENGTH,
731 this, shiftv,
732 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a >>> b)));
733 }
734
735 @Override
736 @ForceInline
737 public Int256Vector aShiftR(Vector<Integer> s) {
738 Int256Vector shiftv = (Int256Vector)s;
739 // As per shift specification for Java, mask the shift count.
740 shiftv = shiftv.and(IntVector.broadcast(SPECIES, 0x1f));
741 return VectorIntrinsics.binaryOp(
742 VECTOR_OP_RSHIFT, Int256Vector.class, int.class, LENGTH,
743 this, shiftv,
744 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a >> b)));
745 }
746 // Ternary operations
747
748
749 // Type specific horizontal reductions
750
751 @Override
752 @ForceInline
753 public int addAll() {
754 return (int) VectorIntrinsics.reductionCoerced(
755 VECTOR_OP_ADD, Int256Vector.class, int.class, LENGTH,
756 this,
757 v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a + b)));
1090
1091 @Override
1092 void forEach(VectorMask<Integer> o, FUnCon f) {
1093 boolean[] mbits = ((Int256Mask)o).getBits();
1094 forEach((i, a) -> {
1095 if (mbits[i]) { f.apply(i, a); }
1096 });
1097 }
1098
1099
1100 Float256Vector toFP() {
1101 int[] vec = getElements();
1102 float[] res = new float[this.species().length()];
1103 for(int i = 0; i < this.species().length(); i++){
1104 res[i] = Float.intBitsToFloat(vec[i]);
1105 }
1106 return new Float256Vector(res);
1107 }
1108
1109 @Override
1110 public Int256Vector rotateEL(int j) {
1111 int[] vec = getElements();
1112 int[] res = new int[length()];
1113 for (int i = 0; i < length(); i++){
1114 res[(j + i) % length()] = vec[i];
1115 }
1116 return new Int256Vector(res);
1117 }
1118
1119 @Override
1120 public Int256Vector rotateER(int j) {
1121 int[] vec = getElements();
1122 int[] res = new int[length()];
1123 for (int i = 0; i < length(); i++){
1124 int z = i - j;
1125 if(j < 0) {
1126 res[length() + z] = vec[i];
1127 } else {
1128 res[z] = vec[i];
1129 }
1130 }
1131 return new Int256Vector(res);
1132 }
1133
1134 @Override
1135 public Int256Vector shiftEL(int j) {
1136 int[] vec = getElements();
1137 int[] res = new int[length()];
1138 for (int i = 0; i < length() - j; i++) {
1139 res[i] = vec[i + j];
1140 }
1141 return new Int256Vector(res);
1142 }
1143
1144 @Override
1145 public Int256Vector shiftER(int j) {
1146 int[] vec = getElements();
1147 int[] res = new int[length()];
1148 for (int i = 0; i < length() - j; i++){
1149 res[i + j] = vec[i];
1150 }
1151 return new Int256Vector(res);
1152 }
1153
1154 @Override
1155 @ForceInline
1156 public Int256Vector rearrange(Vector<Integer> v,
1157 VectorShuffle<Integer> s, VectorMask<Integer> m) {
1158 return this.rearrange(s).blend(v.rearrange(s), m);
1159 }
1160
1161 @Override
1162 @ForceInline
1163 public Int256Vector rearrange(VectorShuffle<Integer> o1) {
1164 Objects.requireNonNull(o1);
1165 Int256Shuffle s = (Int256Shuffle)o1;
|
146
147 @Override
148 int rOp(int v, FBinOp f) {
149 int[] 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 Int256Vector.class,
165 int.class, LENGTH,
166 s.vectorType(),
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.lane(i);
183 }
184 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
185 } else if (stype == short.class) {
186 short[] a = new short[limit];
284 (species, vector) -> vector.defaultReinterpret(species)
285 );
286 } else if (stype == double.class) {
287 return VectorIntrinsics.reinterpret(
288 Int256Vector.class,
289 int.class, LENGTH,
290 Double256Vector.class,
291 double.class, Double256Vector.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 IntVector reshape(VectorSpecies<Integer> s) {
303 Objects.requireNonNull(s);
304 if (s.bitSize() == 64 && (s.vectorType() == Int64Vector.class)) {
305 return VectorIntrinsics.reinterpret(
306 Int256Vector.class,
307 int.class, LENGTH,
308 Int64Vector.class,
309 int.class, Int64Vector.LENGTH,
310 this, s,
311 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
312 );
313 } else if (s.bitSize() == 128 && (s.vectorType() == Int128Vector.class)) {
314 return VectorIntrinsics.reinterpret(
315 Int256Vector.class,
316 int.class, LENGTH,
317 Int128Vector.class,
318 int.class, Int128Vector.LENGTH,
319 this, s,
320 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
321 );
322 } else if (s.bitSize() == 256 && (s.vectorType() == Int256Vector.class)) {
323 return VectorIntrinsics.reinterpret(
324 Int256Vector.class,
325 int.class, LENGTH,
326 Int256Vector.class,
327 int.class, Int256Vector.LENGTH,
328 this, s,
329 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
330 );
331 } else if (s.bitSize() == 512 && (s.vectorType() == Int512Vector.class)) {
332 return VectorIntrinsics.reinterpret(
333 Int256Vector.class,
334 int.class, LENGTH,
335 Int512Vector.class,
336 int.class, Int512Vector.LENGTH,
337 this, s,
338 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
339 );
340 } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
341 && (s.bitSize() % 128 == 0) && (s.vectorType() == IntMaxVector.class)) {
342 return VectorIntrinsics.reinterpret(
343 Int256Vector.class,
344 int.class, LENGTH,
345 IntMaxVector.class,
346 int.class, IntMaxVector.LENGTH,
347 this, s,
348 (species, vector) -> (IntVector) 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 IntVector add(int o) {
360 return add((Int256Vector)IntVector.broadcast(SPECIES, o));
361 }
648 @Override
649 @ForceInline
650 public Int256Vector and(Vector<Integer> v, VectorMask<Integer> m) {
651 return blend(and(v), m);
652 }
653
654 @Override
655 @ForceInline
656 public Int256Vector or(Vector<Integer> v, VectorMask<Integer> m) {
657 return blend(or(v), m);
658 }
659
660 @Override
661 @ForceInline
662 public Int256Vector xor(Vector<Integer> v, VectorMask<Integer> m) {
663 return blend(xor(v), m);
664 }
665
666 @Override
667 @ForceInline
668 public Int256Vector shiftLeft(int s) {
669 return VectorIntrinsics.broadcastInt(
670 VECTOR_OP_LSHIFT, Int256Vector.class, int.class, LENGTH,
671 this, s,
672 (v, i) -> v.uOp((__, a) -> (int) (a << i)));
673 }
674
675 @Override
676 @ForceInline
677 public Int256Vector shiftLeft(int s, VectorMask<Integer> m) {
678 return blend(shiftLeft(s), m);
679 }
680
681 @Override
682 @ForceInline
683 public Int256Vector shiftRight(int s) {
684 return VectorIntrinsics.broadcastInt(
685 VECTOR_OP_URSHIFT, Int256Vector.class, int.class, LENGTH,
686 this, s,
687 (v, i) -> v.uOp((__, a) -> (int) (a >>> i)));
688 }
689
690 @Override
691 @ForceInline
692 public Int256Vector shiftRight(int s, VectorMask<Integer> m) {
693 return blend(shiftRight(s), m);
694 }
695
696 @Override
697 @ForceInline
698 public Int256Vector shiftArithmeticRight(int s) {
699 return VectorIntrinsics.broadcastInt(
700 VECTOR_OP_RSHIFT, Int256Vector.class, int.class, LENGTH,
701 this, s,
702 (v, i) -> v.uOp((__, a) -> (int) (a >> i)));
703 }
704
705 @Override
706 @ForceInline
707 public Int256Vector shiftArithmeticRight(int s, VectorMask<Integer> m) {
708 return blend(shiftArithmeticRight(s), m);
709 }
710
711 @Override
712 @ForceInline
713 public Int256Vector shiftLeft(Vector<Integer> s) {
714 Int256Vector shiftv = (Int256Vector)s;
715 // As per shift specification for Java, mask the shift count.
716 shiftv = shiftv.and(IntVector.broadcast(SPECIES, 0x1f));
717 return VectorIntrinsics.binaryOp(
718 VECTOR_OP_LSHIFT, Int256Vector.class, int.class, LENGTH,
719 this, shiftv,
720 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a << b)));
721 }
722
723 @Override
724 @ForceInline
725 public Int256Vector shiftRight(Vector<Integer> s) {
726 Int256Vector shiftv = (Int256Vector)s;
727 // As per shift specification for Java, mask the shift count.
728 shiftv = shiftv.and(IntVector.broadcast(SPECIES, 0x1f));
729 return VectorIntrinsics.binaryOp(
730 VECTOR_OP_URSHIFT, Int256Vector.class, int.class, LENGTH,
731 this, shiftv,
732 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a >>> b)));
733 }
734
735 @Override
736 @ForceInline
737 public Int256Vector shiftArithmeticRight(Vector<Integer> s) {
738 Int256Vector shiftv = (Int256Vector)s;
739 // As per shift specification for Java, mask the shift count.
740 shiftv = shiftv.and(IntVector.broadcast(SPECIES, 0x1f));
741 return VectorIntrinsics.binaryOp(
742 VECTOR_OP_RSHIFT, Int256Vector.class, int.class, LENGTH,
743 this, shiftv,
744 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a >> b)));
745 }
746 // Ternary operations
747
748
749 // Type specific horizontal reductions
750
751 @Override
752 @ForceInline
753 public int addAll() {
754 return (int) VectorIntrinsics.reductionCoerced(
755 VECTOR_OP_ADD, Int256Vector.class, int.class, LENGTH,
756 this,
757 v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a + b)));
1090
1091 @Override
1092 void forEach(VectorMask<Integer> o, FUnCon f) {
1093 boolean[] mbits = ((Int256Mask)o).getBits();
1094 forEach((i, a) -> {
1095 if (mbits[i]) { f.apply(i, a); }
1096 });
1097 }
1098
1099
1100 Float256Vector toFP() {
1101 int[] vec = getElements();
1102 float[] res = new float[this.species().length()];
1103 for(int i = 0; i < this.species().length(); i++){
1104 res[i] = Float.intBitsToFloat(vec[i]);
1105 }
1106 return new Float256Vector(res);
1107 }
1108
1109 @Override
1110 public Int256Vector rotateLanesLeft(int j) {
1111 int[] vec = getElements();
1112 int[] res = new int[length()];
1113 for (int i = 0; i < length(); i++){
1114 res[(j + i) % length()] = vec[i];
1115 }
1116 return new Int256Vector(res);
1117 }
1118
1119 @Override
1120 public Int256Vector rotateLanesRight(int j) {
1121 int[] vec = getElements();
1122 int[] res = new int[length()];
1123 for (int i = 0; i < length(); i++){
1124 int z = i - j;
1125 if(j < 0) {
1126 res[length() + z] = vec[i];
1127 } else {
1128 res[z] = vec[i];
1129 }
1130 }
1131 return new Int256Vector(res);
1132 }
1133
1134 @Override
1135 public Int256Vector shiftLanesLeft(int j) {
1136 int[] vec = getElements();
1137 int[] res = new int[length()];
1138 for (int i = 0; i < length() - j; i++) {
1139 res[i] = vec[i + j];
1140 }
1141 return new Int256Vector(res);
1142 }
1143
1144 @Override
1145 public Int256Vector shiftLanesRight(int j) {
1146 int[] vec = getElements();
1147 int[] res = new int[length()];
1148 for (int i = 0; i < length() - j; i++){
1149 res[i + j] = vec[i];
1150 }
1151 return new Int256Vector(res);
1152 }
1153
1154 @Override
1155 @ForceInline
1156 public Int256Vector rearrange(Vector<Integer> v,
1157 VectorShuffle<Integer> s, VectorMask<Integer> m) {
1158 return this.rearrange(s).blend(v.rearrange(s), m);
1159 }
1160
1161 @Override
1162 @ForceInline
1163 public Int256Vector rearrange(VectorShuffle<Integer> o1) {
1164 Objects.requireNonNull(o1);
1165 Int256Shuffle s = (Int256Shuffle)o1;
|