< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long512Vector.java

Print this page
rev 55589 : Species-phase2
rev 55591 : XxxSpecies made package private


  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 Long512Vector extends LongVector {
  41     static final Long512Species SPECIES = new Long512Species();
  42 
  43     static final Long512Vector ZERO = new Long512Vector();
  44 
  45     static final int LENGTH = SPECIES.length();
  46 
  47     // Index vector species
  48     private static final IntVector.IntSpecies INDEX_SPEC;

  49     static {
  50         int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
  51         Vector.Shape shape = Shape.forBitSize(bitSize);
  52         INDEX_SPEC = (IntVector.IntSpecies) Species.of(int.class, shape);
  53     }

  54     private final long[] vec; // Don't access directly, use getElements() instead.
  55 
  56     private long[] getElements() {
  57         return VectorIntrinsics.maybeRebox(this).vec;
  58     }
  59 
  60     Long512Vector() {
  61         vec = new long[SPECIES.length()];
  62     }
  63 
  64     Long512Vector(long[] v) {
  65         vec = v;
  66     }
  67 
  68     @Override
  69     public int length() { return LENGTH; }
  70 
  71     // Unary operator
  72 
  73     @Override


 145 
 146     @Override
 147     long rOp(long v, FBinOp f) {
 148         long[] vec = getElements();
 149         for (int i = 0; i < length(); i++) {
 150             v = f.apply(i, v, vec[i]);
 151         }
 152         return v;
 153     }
 154 
 155     @Override
 156     @ForceInline
 157     public <F> Vector<F> cast(Species<F> s) {
 158         Objects.requireNonNull(s);
 159         if (s.length() != LENGTH)
 160             throw new IllegalArgumentException("Vector length this species length differ");
 161 
 162         return VectorIntrinsics.cast(
 163             Long512Vector.class,
 164             long.class, LENGTH,
 165             s.vectorType(),
 166             s.elementType(), LENGTH,
 167             this, s,
 168             (species, vector) -> vector.castDefault(species)
 169         );
 170     }
 171 
 172     @SuppressWarnings("unchecked")
 173     @ForceInline
 174     private <F> Vector<F> castDefault(Species<F> s) {
 175         int limit = s.length();
 176 
 177         Class<?> stype = s.elementType();
 178         if (stype == byte.class) {
 179             byte[] a = new byte[limit];
 180             for (int i = 0; i < limit; i++) {
 181                 a[i] = (byte) this.get(i);
 182             }
 183             return (Vector) ByteVector.fromArray((ByteVector.ByteSpecies) s, a, 0);
 184         } else if (stype == short.class) {
 185             short[] a = new short[limit];
 186             for (int i = 0; i < limit; i++) {
 187                 a[i] = (short) this.get(i);
 188             }
 189             return (Vector) ShortVector.fromArray((ShortVector.ShortSpecies) s, a, 0);
 190         } else if (stype == int.class) {
 191             int[] a = new int[limit];
 192             for (int i = 0; i < limit; i++) {
 193                 a[i] = (int) this.get(i);
 194             }
 195             return (Vector) IntVector.fromArray((IntVector.IntSpecies) s, a, 0);
 196         } else if (stype == long.class) {
 197             long[] a = new long[limit];
 198             for (int i = 0; i < limit; i++) {
 199                 a[i] = (long) this.get(i);
 200             }
 201             return (Vector) LongVector.fromArray((LongVector.LongSpecies) s, a, 0);
 202         } else if (stype == float.class) {
 203             float[] a = new float[limit];
 204             for (int i = 0; i < limit; i++) {
 205                 a[i] = (float) this.get(i);
 206             }
 207             return (Vector) FloatVector.fromArray((FloatVector.FloatSpecies) s, a, 0);
 208         } else if (stype == double.class) {
 209             double[] a = new double[limit];
 210             for (int i = 0; i < limit; i++) {
 211                 a[i] = (double) this.get(i);
 212             }
 213             return (Vector) DoubleVector.fromArray((DoubleVector.DoubleSpecies) s, a, 0);
 214         } else {
 215             throw new UnsupportedOperationException("Bad lane type for casting.");
 216         }
 217     }
 218 
 219     @Override
 220     @ForceInline
 221     @SuppressWarnings("unchecked")
 222     public <F> Vector<F> reinterpret(Species<F> s) {
 223         Objects.requireNonNull(s);
 224 
 225         if(s.elementType().equals(long.class)) {
 226             return (Vector<F>) reshape((Species<Long>)s);
 227         }
 228         if(s.bitSize() == bitSize()) {
 229             return reinterpretType(s);
 230         }
 231 
 232         return defaultReinterpret(s);
 233     }


 283                 (species, vector) -> vector.defaultReinterpret(species)
 284             );
 285         } else if (stype == double.class) {
 286             return VectorIntrinsics.reinterpret(
 287                 Long512Vector.class,
 288                 long.class, LENGTH,
 289                 Double512Vector.class,
 290                 double.class, Double512Vector.LENGTH,
 291                 this, s,
 292                 (species, vector) -> vector.defaultReinterpret(species)
 293             );
 294         } else {
 295             throw new UnsupportedOperationException("Bad lane type for casting.");
 296         }
 297     }
 298 
 299     @Override
 300     @ForceInline
 301     public LongVector reshape(Species<Long> s) {
 302         Objects.requireNonNull(s);
 303         if (s.bitSize() == 64 && (s instanceof Long64Vector.Long64Species)) {
 304             Long64Vector.Long64Species ts = (Long64Vector.Long64Species)s;
 305             return VectorIntrinsics.reinterpret(
 306                 Long512Vector.class,
 307                 long.class, LENGTH,
 308                 Long64Vector.class,
 309                 long.class, Long64Vector.LENGTH,
 310                 this, ts,
 311                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 312             );
 313         } else if (s.bitSize() == 128 && (s instanceof Long128Vector.Long128Species)) {
 314             Long128Vector.Long128Species ts = (Long128Vector.Long128Species)s;
 315             return VectorIntrinsics.reinterpret(
 316                 Long512Vector.class,
 317                 long.class, LENGTH,
 318                 Long128Vector.class,
 319                 long.class, Long128Vector.LENGTH,
 320                 this, ts,
 321                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 322             );
 323         } else if (s.bitSize() == 256 && (s instanceof Long256Vector.Long256Species)) {
 324             Long256Vector.Long256Species ts = (Long256Vector.Long256Species)s;
 325             return VectorIntrinsics.reinterpret(
 326                 Long512Vector.class,
 327                 long.class, LENGTH,
 328                 Long256Vector.class,
 329                 long.class, Long256Vector.LENGTH,
 330                 this, ts,
 331                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 332             );
 333         } else if (s.bitSize() == 512 && (s instanceof Long512Vector.Long512Species)) {
 334             Long512Vector.Long512Species ts = (Long512Vector.Long512Species)s;
 335             return VectorIntrinsics.reinterpret(
 336                 Long512Vector.class,
 337                 long.class, LENGTH,
 338                 Long512Vector.class,
 339                 long.class, Long512Vector.LENGTH,
 340                 this, ts,
 341                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 342             );
 343         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 344                 && (s.bitSize() % 128 == 0) && (s instanceof LongMaxVector.LongMaxSpecies)) {
 345             LongMaxVector.LongMaxSpecies ts = (LongMaxVector.LongMaxSpecies)s;
 346             return VectorIntrinsics.reinterpret(
 347                 Long512Vector.class,
 348                 long.class, LENGTH,
 349                 LongMaxVector.class,
 350                 long.class, LongMaxVector.LENGTH,
 351                 this, ts,
 352                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 353             );
 354         } else {
 355             throw new InternalError("Unimplemented size");
 356         }
 357     }
 358 
 359     // Binary operations with scalars
 360 
 361     @Override
 362     @ForceInline
 363     public LongVector add(long o) {
 364         return add(SPECIES.broadcast(o));
 365     }
 366 
 367     @Override
 368     @ForceInline
 369     public LongVector add(long o, Mask<Long> m) {
 370         return add(SPECIES.broadcast(o), m);
 371     }
 372 
 373     @Override
 374     @ForceInline
 375     public LongVector sub(long o) {
 376         return sub(SPECIES.broadcast(o));
 377     }
 378 
 379     @Override
 380     @ForceInline
 381     public LongVector sub(long o, Mask<Long> m) {
 382         return sub(SPECIES.broadcast(o), m);
 383     }
 384 
 385     @Override
 386     @ForceInline
 387     public LongVector mul(long o) {
 388         return mul(SPECIES.broadcast(o));
 389     }
 390 
 391     @Override
 392     @ForceInline
 393     public LongVector mul(long o, Mask<Long> m) {
 394         return mul(SPECIES.broadcast(o), m);
 395     }
 396 
 397     @Override
 398     @ForceInline
 399     public LongVector min(long o) {
 400         return min(SPECIES.broadcast(o));
 401     }
 402 
 403     @Override
 404     @ForceInline
 405     public LongVector max(long o) {
 406         return max(SPECIES.broadcast(o));
 407     }
 408 
 409     @Override
 410     @ForceInline
 411     public Mask<Long> equal(long o) {
 412         return equal(SPECIES.broadcast(o));
 413     }
 414 
 415     @Override
 416     @ForceInline
 417     public Mask<Long> notEqual(long o) {
 418         return notEqual(SPECIES.broadcast(o));
 419     }
 420 
 421     @Override
 422     @ForceInline
 423     public Mask<Long> lessThan(long o) {
 424         return lessThan(SPECIES.broadcast(o));
 425     }
 426 
 427     @Override
 428     @ForceInline
 429     public Mask<Long> lessThanEq(long o) {
 430         return lessThanEq(SPECIES.broadcast(o));
 431     }
 432 
 433     @Override
 434     @ForceInline
 435     public Mask<Long> greaterThan(long o) {
 436         return greaterThan(SPECIES.broadcast(o));
 437     }
 438 
 439     @Override
 440     @ForceInline
 441     public Mask<Long> greaterThanEq(long o) {
 442         return greaterThanEq(SPECIES.broadcast(o));
 443     }
 444 
 445     @Override
 446     @ForceInline
 447     public LongVector blend(long o, Mask<Long> m) {
 448         return blend(SPECIES.broadcast(o), m);
 449     }
 450 
 451 
 452     @Override
 453     @ForceInline
 454     public LongVector and(long o) {
 455         return and(SPECIES.broadcast(o));
 456     }
 457 
 458     @Override
 459     @ForceInline
 460     public LongVector and(long o, Mask<Long> m) {
 461         return and(SPECIES.broadcast(o), m);
 462     }
 463 
 464     @Override
 465     @ForceInline
 466     public LongVector or(long o) {
 467         return or(SPECIES.broadcast(o));
 468     }
 469 
 470     @Override
 471     @ForceInline
 472     public LongVector or(long o, Mask<Long> m) {
 473         return or(SPECIES.broadcast(o), m);
 474     }
 475 
 476     @Override
 477     @ForceInline
 478     public LongVector xor(long o) {
 479         return xor(SPECIES.broadcast(o));
 480     }
 481 
 482     @Override
 483     @ForceInline
 484     public LongVector xor(long o, Mask<Long> m) {
 485         return xor(SPECIES.broadcast(o), m);
 486     }
 487 
 488     @Override
 489     @ForceInline
 490     public Long512Vector neg() {
 491         return (Long512Vector)zero(SPECIES).sub(this);
 492     }
 493 
 494     // Unary operations
 495 
 496     @ForceInline
 497     @Override
 498     public Long512Vector neg(Mask<Long> m) {
 499         return blend(neg(), m);
 500     }
 501 
 502     @Override
 503     @ForceInline
 504     public Long512Vector abs() {
 505         return VectorIntrinsics.unaryOp(


 700     @Override
 701     @ForceInline
 702     public Long512Vector aShiftR(int s) {
 703         return VectorIntrinsics.broadcastInt(
 704             VECTOR_OP_RSHIFT, Long512Vector.class, long.class, LENGTH,
 705             this, s,
 706             (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
 707     }
 708 
 709     @Override
 710     @ForceInline
 711     public Long512Vector aShiftR(int s, Mask<Long> m) {
 712         return blend(aShiftR(s), m);
 713     }
 714 
 715     @Override
 716     @ForceInline
 717     public Long512Vector shiftL(Vector<Long> s) {
 718         Long512Vector shiftv = (Long512Vector)s;
 719         // As per shift specification for Java, mask the shift count.
 720         shiftv = shiftv.and(species().broadcast(0x3f));
 721         return VectorIntrinsics.binaryOp(
 722             VECTOR_OP_LSHIFT, Long512Vector.class, long.class, LENGTH,
 723             this, shiftv,
 724             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
 725     }
 726 
 727     @Override
 728     @ForceInline
 729     public Long512Vector shiftR(Vector<Long> s) {
 730         Long512Vector shiftv = (Long512Vector)s;
 731         // As per shift specification for Java, mask the shift count.
 732         shiftv = shiftv.and(species().broadcast(0x3f));
 733         return VectorIntrinsics.binaryOp(
 734             VECTOR_OP_URSHIFT, Long512Vector.class, long.class, LENGTH,
 735             this, shiftv,
 736             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >>> b)));
 737     }
 738 
 739     @Override
 740     @ForceInline
 741     public Long512Vector aShiftR(Vector<Long> s) {
 742         Long512Vector shiftv = (Long512Vector)s;
 743         // As per shift specification for Java, mask the shift count.
 744         shiftv = shiftv.and(species().broadcast(0x3f));
 745         return VectorIntrinsics.binaryOp(
 746             VECTOR_OP_RSHIFT, Long512Vector.class, long.class, LENGTH,
 747             this, shiftv,
 748             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >> b)));
 749     }
 750     // Ternary operations
 751 
 752 
 753     // Type specific horizontal reductions
 754 
 755     @Override
 756     @ForceInline
 757     public long addAll() {
 758         return (long) VectorIntrinsics.reductionCoerced(
 759             VECTOR_OP_ADD, Long512Vector.class, long.class, LENGTH,
 760             this,
 761             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a + b)));
 762     }
 763 
 764     @Override
 765     @ForceInline
 766     public long andAll() {
 767         return (long) VectorIntrinsics.reductionCoerced(
 768             VECTOR_OP_AND, Long512Vector.class, long.class, LENGTH,
 769             this,
 770             v -> (long) v.rOp((long) -1, (i, a, b) -> (long) (a & b)));
 771     }
 772 
 773     @Override
 774     @ForceInline
 775     public long andAll(Mask<Long> m) {
 776         return SPECIES.broadcast((long) -1).blend(this, m).andAll();
 777     }
 778 
 779     @Override
 780     @ForceInline
 781     public long minAll() {
 782         return (long) VectorIntrinsics.reductionCoerced(
 783             VECTOR_OP_MIN, Long512Vector.class, long.class, LENGTH,
 784             this,
 785             v -> (long) v.rOp(Long.MAX_VALUE , (i, a, b) -> (long) Math.min(a, b)));
 786     }
 787 
 788     @Override
 789     @ForceInline
 790     public long maxAll() {
 791         return (long) VectorIntrinsics.reductionCoerced(
 792             VECTOR_OP_MAX, Long512Vector.class, long.class, LENGTH,
 793             this,
 794             v -> (long) v.rOp(Long.MIN_VALUE , (i, a, b) -> (long) Math.max(a, b)));
 795     }
 796 


 798     @ForceInline
 799     public long mulAll() {
 800         return (long) VectorIntrinsics.reductionCoerced(
 801             VECTOR_OP_MUL, Long512Vector.class, long.class, LENGTH,
 802             this,
 803             v -> (long) v.rOp((long) 1, (i, a, b) -> (long) (a * b)));
 804     }
 805 
 806     @Override
 807     @ForceInline
 808     public long orAll() {
 809         return (long) VectorIntrinsics.reductionCoerced(
 810             VECTOR_OP_OR, Long512Vector.class, long.class, LENGTH,
 811             this,
 812             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a | b)));
 813     }
 814 
 815     @Override
 816     @ForceInline
 817     public long orAll(Mask<Long> m) {
 818         return SPECIES.broadcast((long) 0).blend(this, m).orAll();
 819     }
 820 
 821     @Override
 822     @ForceInline
 823     public long xorAll() {
 824         return (long) VectorIntrinsics.reductionCoerced(
 825             VECTOR_OP_XOR, Long512Vector.class, long.class, LENGTH,
 826             this,
 827             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a ^ b)));
 828     }
 829 
 830     @Override
 831     @ForceInline
 832     public long xorAll(Mask<Long> m) {
 833         return SPECIES.broadcast((long) 0).blend(this, m).xorAll();
 834     }
 835 
 836 
 837     @Override
 838     @ForceInline
 839     public long addAll(Mask<Long> m) {
 840         return SPECIES.broadcast((long) 0).blend(this, m).addAll();
 841     }
 842 
 843 
 844     @Override
 845     @ForceInline
 846     public long mulAll(Mask<Long> m) {
 847         return SPECIES.broadcast((long) 1).blend(this, m).mulAll();
 848     }
 849 
 850     @Override
 851     @ForceInline
 852     public long minAll(Mask<Long> m) {
 853         return SPECIES.broadcast(Long.MAX_VALUE).blend(this, m).minAll();
 854     }
 855 
 856     @Override
 857     @ForceInline
 858     public long maxAll(Mask<Long> m) {
 859         return SPECIES.broadcast(Long.MIN_VALUE).blend(this, m).maxAll();
 860     }
 861 
 862     @Override
 863     @ForceInline
 864     public Shuffle<Long> toShuffle() {
 865         long[] a = toArray();
 866         int[] sa = new int[a.length];
 867         for (int i = 0; i < a.length; i++) {
 868             sa[i] = (int) a[i];
 869         }
 870         return LongVector.shuffleFromArray(SPECIES, sa, 0);
 871     }
 872 
 873     // Memory operations
 874 
 875     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_LONG_INDEX_SCALE);
 876     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 877 
 878     @Override
 879     @ForceInline


 884                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_LONG_BASE_OFFSET,
 885                                this,
 886                                a, ix,
 887                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 888     }
 889 
 890     @Override
 891     @ForceInline
 892     public final void intoArray(long[] a, int ax, Mask<Long> m) {
 893         LongVector oldVal = LongVector.fromArray(SPECIES, a, ax);
 894         LongVector newVal = oldVal.blend(this, m);
 895         newVal.intoArray(a, ax);
 896     }
 897     @Override
 898     @ForceInline
 899     public void intoArray(long[] a, int ix, int[] b, int iy) {
 900         Objects.requireNonNull(a);
 901         Objects.requireNonNull(b);
 902 
 903         // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
 904         IntVector vix = IntVector.fromArray(INDEX_SPEC, b, iy).add(ix);
 905 
 906         vix = VectorIntrinsics.checkIndex(vix, a.length);
 907 
 908         VectorIntrinsics.storeWithMap(Long512Vector.class, long.class, LENGTH, Int256Vector.class,
 909                                a, Unsafe.ARRAY_LONG_BASE_OFFSET, vix,
 910                                this,
 911                                a, ix, b, iy,
 912                                (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
 913     }
 914 
 915      @Override
 916      @ForceInline
 917      public final void intoArray(long[] a, int ax, Mask<Long> m, int[] b, int iy) {
 918          // @@@ This can result in out of bounds errors for unset mask lanes
 919          LongVector oldVal = LongVector.fromArray(SPECIES, a, ax, b, iy);
 920          LongVector newVal = oldVal.blend(this, m);
 921          newVal.intoArray(a, ax, b, iy);
 922      }
 923 
 924     @Override


1257             boolean[] res = new boolean[species().length()];
1258             boolean[] bits = getBits();
1259             for (int i = 0; i < species().length(); i++) {
1260                 res[i] = f.apply(i, bits[i]);
1261             }
1262             return new Long512Mask(res);
1263         }
1264 
1265         @Override
1266         Long512Mask bOp(Mask<Long> o, MBinOp f) {
1267             boolean[] res = new boolean[species().length()];
1268             boolean[] bits = getBits();
1269             boolean[] mbits = ((Long512Mask)o).getBits();
1270             for (int i = 0; i < species().length(); i++) {
1271                 res[i] = f.apply(i, bits[i], mbits[i]);
1272             }
1273             return new Long512Mask(res);
1274         }
1275 
1276         @Override
1277         public Long512Species species() {
1278             return SPECIES;
1279         }
1280 
1281         @Override
1282         public Long512Vector toVector() {
1283             long[] res = new long[species().length()];
1284             boolean[] bits = getBits();
1285             for (int i = 0; i < species().length(); i++) {
1286                 // -1 will result in the most significant bit being set in
1287                 // addition to some or all other bits
1288                 res[i] = (long) (bits[i] ? -1 : 0);
1289             }
1290             return new Long512Vector(res);
1291         }
1292 

























1293         // Unary operations
1294 
1295         @Override
1296         @ForceInline
1297         public Long512Mask not() {
1298             return (Long512Mask) VectorIntrinsics.unaryOp(
1299                                              VECTOR_OP_NOT, Long512Mask.class, long.class, LENGTH,
1300                                              this,
1301                                              (m1) -> m1.uOp((i, a) -> !a));
1302         }
1303 
1304         // Binary operations
1305 
1306         @Override
1307         @ForceInline
1308         public Long512Mask and(Mask<Long> o) {
1309             Objects.requireNonNull(o);
1310             Long512Mask m = (Long512Mask)o;
1311             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long512Mask.class, long.class, LENGTH,
1312                                              this, m,


1345     // Shuffle
1346 
1347     static final class Long512Shuffle extends AbstractShuffle<Long> {
1348         Long512Shuffle(byte[] reorder) {
1349             super(reorder);
1350         }
1351 
1352         public Long512Shuffle(int[] reorder) {
1353             super(reorder);
1354         }
1355 
1356         public Long512Shuffle(int[] reorder, int i) {
1357             super(reorder, i);
1358         }
1359 
1360         public Long512Shuffle(IntUnaryOperator f) {
1361             super(f);
1362         }
1363 
1364         @Override
1365         public Long512Species species() {
1366             return SPECIES;
1367         }
1368 
1369         @Override
1370         public LongVector toVector() {
1371             long[] va = new long[SPECIES.length()];
1372             for (int i = 0; i < va.length; i++) {
1373               va[i] = (long) getElement(i);
1374             }
1375             return LongVector.fromArray(SPECIES, va, 0);
1376         }
1377 
1378         @Override

























1379         public Long512Shuffle rearrange(Vector.Shuffle<Long> o) {
1380             Long512Shuffle s = (Long512Shuffle) o;
1381             byte[] r = new byte[reorder.length];
1382             for (int i = 0; i < reorder.length; i++) {
1383                 r[i] = reorder[s.reorder[i]];
1384             }
1385             return new Long512Shuffle(r);
1386         }
1387     }
1388 
1389     // Species
1390 
1391     @Override
1392     public Long512Species species() {
1393         return SPECIES;
1394     }
1395 
1396     static final class Long512Species extends LongSpecies {
1397         static final int BIT_SIZE = Shape.S_512_BIT.bitSize();
1398 
1399         static final int LENGTH = BIT_SIZE / Long.SIZE;
1400 
1401         @Override
1402         public String toString() {
1403            StringBuilder sb = new StringBuilder("Shape[");
1404            sb.append(bitSize()).append(" bits, ");
1405            sb.append(length()).append(" ").append(long.class.getSimpleName()).append("s x ");
1406            sb.append(elementSize()).append(" bits");
1407            sb.append("]");
1408            return sb.toString();
1409         }
1410 
1411         @Override
1412         @ForceInline
1413         public int bitSize() {
1414             return BIT_SIZE;
1415         }
1416 
1417         @Override
1418         @ForceInline
1419         public int length() {
1420             return LENGTH;
1421         }
1422 
1423         @Override
1424         @ForceInline
1425         public Class<Long> elementType() {
1426             return long.class;
1427         }
1428 
1429         @Override
1430         @ForceInline
1431         public Class<?> boxType() {
1432             return Long512Vector.class;
1433         }
1434 
1435         @Override
1436         @ForceInline
1437         public Class<?> maskType() {
1438             return Long512Mask.class;
1439         }
1440 
1441         @Override
1442         @ForceInline
1443         public int elementSize() {
1444             return Long.SIZE;
1445         }
1446 
1447         @Override
1448         @ForceInline
1449         @SuppressWarnings("unchecked")
1450         Class<?> vectorType() {
1451             return Long512Vector.class;
1452         }
1453 
1454         @Override
1455         @ForceInline
1456         public Shape shape() {
1457             return Shape.S_512_BIT;
1458         }
1459 
1460        @Override
1461        IntVector.IntSpecies indexSpecies() {
1462           return INDEX_SPEC;
1463        }
1464 
1465         @Override
1466         Long512Vector op(FOp f) {
1467             long[] res = new long[length()];
1468             for (int i = 0; i < length(); i++) {
1469                 res[i] = f.apply(i);
1470             }
1471             return new Long512Vector(res);
1472         }
1473 
1474         @Override
1475         Long512Vector op(Mask<Long> o, FOp f) {
1476             long[] res = new long[length()];
1477             boolean[] mbits = ((Long512Mask)o).getBits();
1478             for (int i = 0; i < length(); i++) {
1479                 if (mbits[i]) {
1480                     res[i] = f.apply(i);
1481                 }
1482             }
1483             return new Long512Vector(res);
1484         }
1485 
1486         @Override
1487         Long512Mask opm(FOpm f) {
1488             boolean[] res = new boolean[length()];
1489             for (int i = 0; i < length(); i++) {
1490                 res[i] = (boolean)f.apply(i);
1491             }
1492             return new Long512Mask(res);
1493         }
1494 
1495         // Factories
1496 
1497         @Override
1498         @ForceInline
1499         public Long512Vector zero() {
1500             return VectorIntrinsics.broadcastCoerced(Long512Vector.class, long.class, LENGTH,
1501                                                      0, SPECIES,
1502                                                      ((bits, s) -> ((Long512Species)s).op(i -> (long)bits)));
1503         }
1504 
1505         @Override
1506         @ForceInline
1507         public Long512Vector broadcast(long e) {
1508             return VectorIntrinsics.broadcastCoerced(
1509                 Long512Vector.class, long.class, LENGTH,
1510                 e, SPECIES,
1511                 ((bits, s) -> ((Long512Species)s).op(i -> (long)bits)));
1512         }
1513 
1514         @Override
1515         @ForceInline
1516         public Long512Vector scalars(long... es) {
1517             Objects.requireNonNull(es);
1518             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1519             return VectorIntrinsics.load(Long512Vector.class, long.class, LENGTH,
1520                                          es, Unsafe.ARRAY_LONG_BASE_OFFSET,
1521                                          es, ix, SPECIES,
1522                                          (c, idx, s) -> ((Long512Species)s).op(n -> c[idx + n]));
1523         }
1524 
1525         @Override
1526         @ForceInline
1527         public <E> Long512Mask cast(Mask<E> m) {
1528             if (m.length() != LENGTH)
1529                 throw new IllegalArgumentException("Mask length this species length differ");
1530             return new Long512Mask(m.toArray());
1531         }
1532 
1533         @Override
1534         @ForceInline
1535         public <E> Long512Shuffle cast(Shuffle<E> s) {
1536             if (s.length() != LENGTH)
1537                 throw new IllegalArgumentException("Shuffle length this species length differ");
1538             return new Long512Shuffle(s.toArray());
1539         }
1540     }
1541 }


  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 Long512Vector extends LongVector {
  41     private static final Species<Long> SPECIES = LongVector.SPECIES_512;
  42 
  43     static final Long512Vector ZERO = new Long512Vector();
  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     Long512Vector() {
  62         vec = new long[SPECIES.length()];
  63     }
  64 
  65     Long512Vector(long[] v) {
  66         vec = v;
  67     }
  68 
  69     @Override
  70     public int length() { return LENGTH; }
  71 
  72     // Unary operator
  73 
  74     @Override


 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             Long512Vector.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     }


 284                 (species, vector) -> vector.defaultReinterpret(species)
 285             );
 286         } else if (stype == double.class) {
 287             return VectorIntrinsics.reinterpret(
 288                 Long512Vector.class,
 289                 long.class, LENGTH,
 290                 Double512Vector.class,
 291                 double.class, Double512Vector.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                 Long512Vector.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                 Long512Vector.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)) {

 323             return VectorIntrinsics.reinterpret(
 324                 Long512Vector.class,
 325                 long.class, LENGTH,
 326                 Long256Vector.class,
 327                 long.class, Long256Vector.LENGTH,
 328                 this, s,
 329                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 330             );
 331         } else if (s.bitSize() == 512 && (s.boxType() == Long512Vector.class)) {

 332             return VectorIntrinsics.reinterpret(
 333                 Long512Vector.class,
 334                 long.class, LENGTH,
 335                 Long512Vector.class,
 336                 long.class, Long512Vector.LENGTH,
 337                 this, s,
 338                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 339             );
 340         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 341                 && (s.bitSize() % 128 == 0) && (s.boxType() == LongMaxVector.class)) {

 342             return VectorIntrinsics.reinterpret(
 343                 Long512Vector.class,
 344                 long.class, LENGTH,
 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((Long512Vector)LongVector.broadcast(SPECIES, o));
 361     }
 362 
 363     @Override
 364     @ForceInline
 365     public LongVector add(long o, Mask<Long> m) {
 366         return add((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 367     }
 368 
 369     @Override
 370     @ForceInline
 371     public LongVector sub(long o) {
 372         return sub((Long512Vector)LongVector.broadcast(SPECIES, o));
 373     }
 374 
 375     @Override
 376     @ForceInline
 377     public LongVector sub(long o, Mask<Long> m) {
 378         return sub((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 379     }
 380 
 381     @Override
 382     @ForceInline
 383     public LongVector mul(long o) {
 384         return mul((Long512Vector)LongVector.broadcast(SPECIES, o));
 385     }
 386 
 387     @Override
 388     @ForceInline
 389     public LongVector mul(long o, Mask<Long> m) {
 390         return mul((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 391     }
 392 
 393     @Override
 394     @ForceInline
 395     public LongVector min(long o) {
 396         return min((Long512Vector)LongVector.broadcast(SPECIES, o));
 397     }
 398 
 399     @Override
 400     @ForceInline
 401     public LongVector max(long o) {
 402         return max((Long512Vector)LongVector.broadcast(SPECIES, o));
 403     }
 404 
 405     @Override
 406     @ForceInline
 407     public Mask<Long> equal(long o) {
 408         return equal((Long512Vector)LongVector.broadcast(SPECIES, o));
 409     }
 410 
 411     @Override
 412     @ForceInline
 413     public Mask<Long> notEqual(long o) {
 414         return notEqual((Long512Vector)LongVector.broadcast(SPECIES, o));
 415     }
 416 
 417     @Override
 418     @ForceInline
 419     public Mask<Long> lessThan(long o) {
 420         return lessThan((Long512Vector)LongVector.broadcast(SPECIES, o));
 421     }
 422 
 423     @Override
 424     @ForceInline
 425     public Mask<Long> lessThanEq(long o) {
 426         return lessThanEq((Long512Vector)LongVector.broadcast(SPECIES, o));
 427     }
 428 
 429     @Override
 430     @ForceInline
 431     public Mask<Long> greaterThan(long o) {
 432         return greaterThan((Long512Vector)LongVector.broadcast(SPECIES, o));
 433     }
 434 
 435     @Override
 436     @ForceInline
 437     public Mask<Long> greaterThanEq(long o) {
 438         return greaterThanEq((Long512Vector)LongVector.broadcast(SPECIES, o));
 439     }
 440 
 441     @Override
 442     @ForceInline
 443     public LongVector blend(long o, Mask<Long> m) {
 444         return blend((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 445     }
 446 
 447 
 448     @Override
 449     @ForceInline
 450     public LongVector and(long o) {
 451         return and((Long512Vector)LongVector.broadcast(SPECIES, o));
 452     }
 453 
 454     @Override
 455     @ForceInline
 456     public LongVector and(long o, Mask<Long> m) {
 457         return and((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 458     }
 459 
 460     @Override
 461     @ForceInline
 462     public LongVector or(long o) {
 463         return or((Long512Vector)LongVector.broadcast(SPECIES, o));
 464     }
 465 
 466     @Override
 467     @ForceInline
 468     public LongVector or(long o, Mask<Long> m) {
 469         return or((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 470     }
 471 
 472     @Override
 473     @ForceInline
 474     public LongVector xor(long o) {
 475         return xor((Long512Vector)LongVector.broadcast(SPECIES, o));
 476     }
 477 
 478     @Override
 479     @ForceInline
 480     public LongVector xor(long o, Mask<Long> m) {
 481         return xor((Long512Vector)LongVector.broadcast(SPECIES, o), m);
 482     }
 483 
 484     @Override
 485     @ForceInline
 486     public Long512Vector neg() {
 487         return (Long512Vector)zero(SPECIES).sub(this);
 488     }
 489 
 490     // Unary operations
 491 
 492     @ForceInline
 493     @Override
 494     public Long512Vector neg(Mask<Long> m) {
 495         return blend(neg(), m);
 496     }
 497 
 498     @Override
 499     @ForceInline
 500     public Long512Vector abs() {
 501         return VectorIntrinsics.unaryOp(


 696     @Override
 697     @ForceInline
 698     public Long512Vector aShiftR(int s) {
 699         return VectorIntrinsics.broadcastInt(
 700             VECTOR_OP_RSHIFT, Long512Vector.class, long.class, LENGTH,
 701             this, s,
 702             (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
 703     }
 704 
 705     @Override
 706     @ForceInline
 707     public Long512Vector aShiftR(int s, Mask<Long> m) {
 708         return blend(aShiftR(s), m);
 709     }
 710 
 711     @Override
 712     @ForceInline
 713     public Long512Vector shiftL(Vector<Long> s) {
 714         Long512Vector shiftv = (Long512Vector)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, Long512Vector.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 Long512Vector shiftR(Vector<Long> s) {
 726         Long512Vector shiftv = (Long512Vector)s;
 727         // As per shift specification for Java, mask the shift count.
 728         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 729         return VectorIntrinsics.binaryOp(
 730             VECTOR_OP_URSHIFT, Long512Vector.class, long.class, LENGTH,
 731             this, shiftv,
 732             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >>> b)));
 733     }
 734 
 735     @Override
 736     @ForceInline
 737     public Long512Vector aShiftR(Vector<Long> s) {
 738         Long512Vector shiftv = (Long512Vector)s;
 739         // As per shift specification for Java, mask the shift count.
 740         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 741         return VectorIntrinsics.binaryOp(
 742             VECTOR_OP_RSHIFT, Long512Vector.class, long.class, LENGTH,
 743             this, shiftv,
 744             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >> b)));
 745     }
 746     // Ternary operations
 747 
 748 
 749     // Type specific horizontal reductions
 750 
 751     @Override
 752     @ForceInline
 753     public long addAll() {
 754         return (long) VectorIntrinsics.reductionCoerced(
 755             VECTOR_OP_ADD, Long512Vector.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, Long512Vector.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((Long512Vector)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, Long512Vector.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, Long512Vector.class, long.class, LENGTH,
 789             this,
 790             v -> (long) v.rOp(Long.MIN_VALUE , (i, a, b) -> (long) Math.max(a, b)));
 791     }
 792 


 794     @ForceInline
 795     public long mulAll() {
 796         return (long) VectorIntrinsics.reductionCoerced(
 797             VECTOR_OP_MUL, Long512Vector.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, Long512Vector.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((Long512Vector)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, Long512Vector.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((Long512Vector)LongVector.broadcast(SPECIES, (long) 0), m).xorAll();
 830     }
 831 
 832 
 833     @Override
 834     @ForceInline
 835     public long addAll(Mask<Long> m) {
 836         return blend((Long512Vector)LongVector.broadcast(SPECIES, (long) 0), m).addAll();
 837     }
 838 
 839 
 840     @Override
 841     @ForceInline
 842     public long mulAll(Mask<Long> m) {
 843         return blend((Long512Vector)LongVector.broadcast(SPECIES, (long) 1), m).mulAll();
 844     }
 845 
 846     @Override
 847     @ForceInline
 848     public long minAll(Mask<Long> m) {
 849         return blend((Long512Vector)LongVector.broadcast(SPECIES, Long.MAX_VALUE), m).minAll();
 850     }
 851 
 852     @Override
 853     @ForceInline
 854     public long maxAll(Mask<Long> m) {
 855         return blend((Long512Vector)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


 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(Long512Vector.class, long.class, LENGTH, Int256Vector.class,
 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


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 Long512Mask(res);
1259         }
1260 
1261         @Override
1262         Long512Mask bOp(Mask<Long> o, MBinOp f) {
1263             boolean[] res = new boolean[species().length()];
1264             boolean[] bits = getBits();
1265             boolean[] mbits = ((Long512Mask)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 Long512Mask(res);
1270         }
1271 
1272         @Override
1273         public Species<Long> species() {
1274             return SPECIES;
1275         }
1276 
1277         @Override
1278         public Long512Vector 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 Long512Vector(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 Byte512Vector.Byte512Mask(maskArray);
1299             } else if (stype == short.class) {
1300                 return (Mask <E>) new Short512Vector.Short512Mask(maskArray);
1301             } else if (stype == int.class) {
1302                 return (Mask <E>) new Int512Vector.Int512Mask(maskArray);
1303             } else if (stype == long.class) {
1304                 return (Mask <E>) new Long512Vector.Long512Mask(maskArray);
1305             } else if (stype == float.class) {
1306                 return (Mask <E>) new Float512Vector.Float512Mask(maskArray);
1307             } else if (stype == double.class) {
1308                 return (Mask <E>) new Double512Vector.Double512Mask(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 Long512Mask not() {
1319             return (Long512Mask) VectorIntrinsics.unaryOp(
1320                                              VECTOR_OP_NOT, Long512Mask.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 Long512Mask and(Mask<Long> o) {
1330             Objects.requireNonNull(o);
1331             Long512Mask m = (Long512Mask)o;
1332             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long512Mask.class, long.class, LENGTH,
1333                                              this, m,


1366     // Shuffle
1367 
1368     static final class Long512Shuffle extends AbstractShuffle<Long> {
1369         Long512Shuffle(byte[] reorder) {
1370             super(reorder);
1371         }
1372 
1373         public Long512Shuffle(int[] reorder) {
1374             super(reorder);
1375         }
1376 
1377         public Long512Shuffle(int[] reorder, int i) {
1378             super(reorder, i);
1379         }
1380 
1381         public Long512Shuffle(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 Byte512Vector.Byte512Shuffle(shuffleArray);
1409             } else if (stype == short.class) {
1410                 return (Shuffle<F>) new Short512Vector.Short512Shuffle(shuffleArray);
1411             } else if (stype == int.class) {
1412                 return (Shuffle<F>) new Int512Vector.Int512Shuffle(shuffleArray);
1413             } else if (stype == long.class) {
1414                 return (Shuffle<F>) new Long512Vector.Long512Shuffle(shuffleArray);
1415             } else if (stype == float.class) {
1416                 return (Shuffle<F>) new Float512Vector.Float512Shuffle(shuffleArray);
1417             } else if (stype == double.class) {
1418                 return (Shuffle<F>) new Double512Vector.Double512Shuffle(shuffleArray);
1419             } else {
1420                 throw new UnsupportedOperationException("Bad lane type for casting.");
1421             }
1422         }
1423 
1424         @Override
1425         public Long512Shuffle rearrange(Vector.Shuffle<Long> o) {
1426             Long512Shuffle s = (Long512Shuffle) 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 Long512Shuffle(r);
1432         }
1433     }
1434 
1435     // Species
1436 
1437     @Override
1438     public Species<Long> species() {
1439         return SPECIES;


















































































































































1440     }
1441 }
< prev index next >