< prev index next >

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

  49     static {
  50         INDEX_SPEC = (IntVector.IntSpecies) Species.of(int.class, Shape.S_64_BIT);
  51     }

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


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


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


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


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


1243             boolean[] res = new boolean[species().length()];
1244             boolean[] bits = getBits();
1245             for (int i = 0; i < species().length(); i++) {
1246                 res[i] = f.apply(i, bits[i]);
1247             }
1248             return new Long64Mask(res);
1249         }
1250 
1251         @Override
1252         Long64Mask bOp(Mask<Long> o, MBinOp f) {
1253             boolean[] res = new boolean[species().length()];
1254             boolean[] bits = getBits();
1255             boolean[] mbits = ((Long64Mask)o).getBits();
1256             for (int i = 0; i < species().length(); i++) {
1257                 res[i] = f.apply(i, bits[i], mbits[i]);
1258             }
1259             return new Long64Mask(res);
1260         }
1261 
1262         @Override
1263         public Long64Species species() {
1264             return SPECIES;
1265         }
1266 
1267         @Override
1268         public Long64Vector toVector() {
1269             long[] res = new long[species().length()];
1270             boolean[] bits = getBits();
1271             for (int i = 0; i < species().length(); i++) {
1272                 // -1 will result in the most significant bit being set in
1273                 // addition to some or all other bits
1274                 res[i] = (long) (bits[i] ? -1 : 0);
1275             }
1276             return new Long64Vector(res);
1277         }
1278 

























1279         // Unary operations
1280 
1281         @Override
1282         @ForceInline
1283         public Long64Mask not() {
1284             return (Long64Mask) VectorIntrinsics.unaryOp(
1285                                              VECTOR_OP_NOT, Long64Mask.class, long.class, LENGTH,
1286                                              this,
1287                                              (m1) -> m1.uOp((i, a) -> !a));
1288         }
1289 
1290         // Binary operations
1291 
1292         @Override
1293         @ForceInline
1294         public Long64Mask and(Mask<Long> o) {
1295             Objects.requireNonNull(o);
1296             Long64Mask m = (Long64Mask)o;
1297             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long64Mask.class, long.class, LENGTH,
1298                                              this, m,


1331     // Shuffle
1332 
1333     static final class Long64Shuffle extends AbstractShuffle<Long> {
1334         Long64Shuffle(byte[] reorder) {
1335             super(reorder);
1336         }
1337 
1338         public Long64Shuffle(int[] reorder) {
1339             super(reorder);
1340         }
1341 
1342         public Long64Shuffle(int[] reorder, int i) {
1343             super(reorder, i);
1344         }
1345 
1346         public Long64Shuffle(IntUnaryOperator f) {
1347             super(f);
1348         }
1349 
1350         @Override
1351         public Long64Species species() {
1352             return SPECIES;
1353         }
1354 
1355         @Override
1356         public LongVector toVector() {
1357             long[] va = new long[SPECIES.length()];
1358             for (int i = 0; i < va.length; i++) {
1359               va[i] = (long) getElement(i);
1360             }
1361             return LongVector.fromArray(SPECIES, va, 0);
1362         }
1363 
1364         @Override

























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


  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 Long64Vector extends LongVector {
  41     private static final Species<Long> SPECIES = LongVector.SPECIES_64;
  42 
  43     static final Long64Vector ZERO = new Long64Vector();
  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         INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.S_64_BIT);
  52     }
  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     Long64Vector() {
  61         vec = new long[SPECIES.length()];
  62     }
  63 
  64     Long64Vector(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             Long64Vector.class,
 164             long.class, LENGTH,
 165             s.boxType(),
 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((Species<Byte>) 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((Species<Short>) 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((Species<Integer>) 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((Species<Long>) 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((Species<Float>) 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((Species<Double>) 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                 Long64Vector.class,
 288                 long.class, LENGTH,
 289                 Double64Vector.class,
 290                 double.class, Double64Vector.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.boxType() == Long64Vector.class)) {

 304             return VectorIntrinsics.reinterpret(
 305                 Long64Vector.class,
 306                 long.class, LENGTH,
 307                 Long64Vector.class,
 308                 long.class, Long64Vector.LENGTH,
 309                 this, s,
 310                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 311             );
 312         } else if (s.bitSize() == 128 && (s.boxType() == Long128Vector.class)) {

 313             return VectorIntrinsics.reinterpret(
 314                 Long64Vector.class,
 315                 long.class, LENGTH,
 316                 Long128Vector.class,
 317                 long.class, Long128Vector.LENGTH,
 318                 this, s,
 319                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 320             );
 321         } else if (s.bitSize() == 256 && (s.boxType() == Long256Vector.class)) {

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

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

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


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


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


1240             boolean[] res = new boolean[species().length()];
1241             boolean[] bits = getBits();
1242             for (int i = 0; i < species().length(); i++) {
1243                 res[i] = f.apply(i, bits[i]);
1244             }
1245             return new Long64Mask(res);
1246         }
1247 
1248         @Override
1249         Long64Mask bOp(Mask<Long> o, MBinOp f) {
1250             boolean[] res = new boolean[species().length()];
1251             boolean[] bits = getBits();
1252             boolean[] mbits = ((Long64Mask)o).getBits();
1253             for (int i = 0; i < species().length(); i++) {
1254                 res[i] = f.apply(i, bits[i], mbits[i]);
1255             }
1256             return new Long64Mask(res);
1257         }
1258 
1259         @Override
1260         public Species<Long> species() {
1261             return SPECIES;
1262         }
1263 
1264         @Override
1265         public Long64Vector toVector() {
1266             long[] res = new long[species().length()];
1267             boolean[] bits = getBits();
1268             for (int i = 0; i < species().length(); i++) {
1269                 // -1 will result in the most significant bit being set in
1270                 // addition to some or all other bits
1271                 res[i] = (long) (bits[i] ? -1 : 0);
1272             }
1273             return new Long64Vector(res);
1274         }
1275 
1276         @Override
1277         @ForceInline
1278         @SuppressWarnings("unchecked")
1279         public <E> Mask<E> cast(Species<E> species) {
1280             if (length() != species.length())
1281                 throw new IllegalArgumentException("Mask length and species length differ");
1282             Class<?> stype = species.elementType();
1283             boolean [] maskArray = toArray();
1284             if (stype == byte.class) {
1285                 return (Mask <E>) new Byte64Vector.Byte64Mask(maskArray);
1286             } else if (stype == short.class) {
1287                 return (Mask <E>) new Short64Vector.Short64Mask(maskArray);
1288             } else if (stype == int.class) {
1289                 return (Mask <E>) new Int64Vector.Int64Mask(maskArray);
1290             } else if (stype == long.class) {
1291                 return (Mask <E>) new Long64Vector.Long64Mask(maskArray);
1292             } else if (stype == float.class) {
1293                 return (Mask <E>) new Float64Vector.Float64Mask(maskArray);
1294             } else if (stype == double.class) {
1295                 return (Mask <E>) new Double64Vector.Double64Mask(maskArray);
1296             } else {
1297                 throw new UnsupportedOperationException("Bad lane type for casting.");
1298             }
1299         }
1300 
1301         // Unary operations
1302 
1303         @Override
1304         @ForceInline
1305         public Long64Mask not() {
1306             return (Long64Mask) VectorIntrinsics.unaryOp(
1307                                              VECTOR_OP_NOT, Long64Mask.class, long.class, LENGTH,
1308                                              this,
1309                                              (m1) -> m1.uOp((i, a) -> !a));
1310         }
1311 
1312         // Binary operations
1313 
1314         @Override
1315         @ForceInline
1316         public Long64Mask and(Mask<Long> o) {
1317             Objects.requireNonNull(o);
1318             Long64Mask m = (Long64Mask)o;
1319             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long64Mask.class, long.class, LENGTH,
1320                                              this, m,


1353     // Shuffle
1354 
1355     static final class Long64Shuffle extends AbstractShuffle<Long> {
1356         Long64Shuffle(byte[] reorder) {
1357             super(reorder);
1358         }
1359 
1360         public Long64Shuffle(int[] reorder) {
1361             super(reorder);
1362         }
1363 
1364         public Long64Shuffle(int[] reorder, int i) {
1365             super(reorder, i);
1366         }
1367 
1368         public Long64Shuffle(IntUnaryOperator f) {
1369             super(f);
1370         }
1371 
1372         @Override
1373         public Species<Long> species() {
1374             return SPECIES;
1375         }
1376 
1377         @Override
1378         public LongVector toVector() {
1379             long[] va = new long[SPECIES.length()];
1380             for (int i = 0; i < va.length; i++) {
1381               va[i] = (long) getElement(i);
1382             }
1383             return LongVector.fromArray(SPECIES, va, 0);
1384         }
1385 
1386         @Override
1387         @ForceInline
1388         @SuppressWarnings("unchecked")
1389         public <F> Shuffle<F> cast(Species<F> species) {
1390             if (length() != species.length())
1391                 throw new IllegalArgumentException("Shuffle length and species length differ");
1392             Class<?> stype = species.elementType();
1393             int [] shuffleArray = toArray();
1394             if (stype == byte.class) {
1395                 return (Shuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1396             } else if (stype == short.class) {
1397                 return (Shuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1398             } else if (stype == int.class) {
1399                 return (Shuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1400             } else if (stype == long.class) {
1401                 return (Shuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
1402             } else if (stype == float.class) {
1403                 return (Shuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
1404             } else if (stype == double.class) {
1405                 return (Shuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
1406             } else {
1407                 throw new UnsupportedOperationException("Bad lane type for casting.");
1408             }
1409         }
1410 
1411         @Override
1412         public Long64Shuffle rearrange(Vector.Shuffle<Long> o) {
1413             Long64Shuffle s = (Long64Shuffle) o;
1414             byte[] r = new byte[reorder.length];
1415             for (int i = 0; i < reorder.length; i++) {
1416                 r[i] = reorder[s.reorder[i]];
1417             }
1418             return new Long64Shuffle(r);
1419         }
1420     }
1421 
1422     // Species
1423 
1424     @Override
1425     public Species<Long> species() {
1426         return SPECIES;


















































































































































1427     }
1428 }
< prev index next >