1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have
  23  * questions.
  24  */
  25 package jdk.incubator.vector;
  26 
  27 import java.nio.ByteBuffer;
  28 import java.nio.ByteOrder;
  29 import java.nio.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
  72     Long64Vector uOp(FUnOp f) {
  73         long[] vec = getElements();
  74         long[] res = new long[length()];
  75         for (int i = 0; i < length(); i++) {
  76             res[i] = f.apply(i, vec[i]);
  77         }
  78         return new Long64Vector(res);
  79     }
  80 
  81     @Override
  82     Long64Vector uOp(Mask<Long> o, FUnOp f) {
  83         long[] vec = getElements();
  84         long[] res = new long[length()];
  85         boolean[] mbits = ((Long64Mask)o).getBits();
  86         for (int i = 0; i < length(); i++) {
  87             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
  88         }
  89         return new Long64Vector(res);
  90     }
  91 
  92     // Binary operator
  93 
  94     @Override
  95     Long64Vector bOp(Vector<Long> o, FBinOp f) {
  96         long[] res = new long[length()];
  97         long[] vec1 = this.getElements();
  98         long[] vec2 = ((Long64Vector)o).getElements();
  99         for (int i = 0; i < length(); i++) {
 100             res[i] = f.apply(i, vec1[i], vec2[i]);
 101         }
 102         return new Long64Vector(res);
 103     }
 104 
 105     @Override
 106     Long64Vector bOp(Vector<Long> o1, Mask<Long> o2, FBinOp f) {
 107         long[] res = new long[length()];
 108         long[] vec1 = this.getElements();
 109         long[] vec2 = ((Long64Vector)o1).getElements();
 110         boolean[] mbits = ((Long64Mask)o2).getBits();
 111         for (int i = 0; i < length(); i++) {
 112             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
 113         }
 114         return new Long64Vector(res);
 115     }
 116 
 117     // Trinary operator
 118 
 119     @Override
 120     Long64Vector tOp(Vector<Long> o1, Vector<Long> o2, FTriOp f) {
 121         long[] res = new long[length()];
 122         long[] vec1 = this.getElements();
 123         long[] vec2 = ((Long64Vector)o1).getElements();
 124         long[] vec3 = ((Long64Vector)o2).getElements();
 125         for (int i = 0; i < length(); i++) {
 126             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
 127         }
 128         return new Long64Vector(res);
 129     }
 130 
 131     @Override
 132     Long64Vector tOp(Vector<Long> o1, Vector<Long> o2, Mask<Long> o3, FTriOp f) {
 133         long[] res = new long[length()];
 134         long[] vec1 = getElements();
 135         long[] vec2 = ((Long64Vector)o1).getElements();
 136         long[] vec3 = ((Long64Vector)o2).getElements();
 137         boolean[] mbits = ((Long64Mask)o3).getBits();
 138         for (int i = 0; i < length(); i++) {
 139             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
 140         }
 141         return new Long64Vector(res);
 142     }
 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     }
 232 
 233     @ForceInline
 234     private <F> Vector<F> reinterpretType(Species<F> s) {
 235         Objects.requireNonNull(s);
 236 
 237         Class<?> stype = s.elementType();
 238         if (stype == byte.class) {
 239             return VectorIntrinsics.reinterpret(
 240                 Long64Vector.class,
 241                 long.class, LENGTH,
 242                 Byte64Vector.class,
 243                 byte.class, Byte64Vector.LENGTH,
 244                 this, s,
 245                 (species, vector) -> vector.defaultReinterpret(species)
 246             );
 247         } else if (stype == short.class) {
 248             return VectorIntrinsics.reinterpret(
 249                 Long64Vector.class,
 250                 long.class, LENGTH,
 251                 Short64Vector.class,
 252                 short.class, Short64Vector.LENGTH,
 253                 this, s,
 254                 (species, vector) -> vector.defaultReinterpret(species)
 255             );
 256         } else if (stype == int.class) {
 257             return VectorIntrinsics.reinterpret(
 258                 Long64Vector.class,
 259                 long.class, LENGTH,
 260                 Int64Vector.class,
 261                 int.class, Int64Vector.LENGTH,
 262                 this, s,
 263                 (species, vector) -> vector.defaultReinterpret(species)
 264             );
 265         } else if (stype == long.class) {
 266             return VectorIntrinsics.reinterpret(
 267                 Long64Vector.class,
 268                 long.class, LENGTH,
 269                 Long64Vector.class,
 270                 long.class, Long64Vector.LENGTH,
 271                 this, s,
 272                 (species, vector) -> vector.defaultReinterpret(species)
 273             );
 274         } else if (stype == float.class) {
 275             return VectorIntrinsics.reinterpret(
 276                 Long64Vector.class,
 277                 long.class, LENGTH,
 278                 Float64Vector.class,
 279                 float.class, Float64Vector.LENGTH,
 280                 this, s,
 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(
 504             VECTOR_OP_ABS, Long64Vector.class, long.class, LENGTH,
 505             this,
 506             v1 -> v1.uOp((i, a) -> (long) Math.abs(a)));
 507     }
 508 
 509     @ForceInline
 510     @Override
 511     public Long64Vector abs(Mask<Long> m) {
 512         return blend(abs(), m);
 513     }
 514 
 515 
 516     @Override
 517     @ForceInline
 518     public Long64Vector not() {
 519         return VectorIntrinsics.unaryOp(
 520             VECTOR_OP_NOT, Long64Vector.class, long.class, LENGTH,
 521             this,
 522             v1 -> v1.uOp((i, a) -> (long) ~a));
 523     }
 524 
 525     @ForceInline
 526     @Override
 527     public Long64Vector not(Mask<Long> m) {
 528         return blend(not(), m);
 529     }
 530     // Binary operations
 531 
 532     @Override
 533     @ForceInline
 534     public Long64Vector add(Vector<Long> o) {
 535         Objects.requireNonNull(o);
 536         Long64Vector v = (Long64Vector)o;
 537         return VectorIntrinsics.binaryOp(
 538             VECTOR_OP_ADD, Long64Vector.class, long.class, LENGTH,
 539             this, v,
 540             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a + b)));
 541     }
 542 
 543     @Override
 544     @ForceInline
 545     public Long64Vector add(Vector<Long> v, Mask<Long> m) {
 546         return blend(add(v), m);
 547     }
 548 
 549     @Override
 550     @ForceInline
 551     public Long64Vector sub(Vector<Long> o) {
 552         Objects.requireNonNull(o);
 553         Long64Vector v = (Long64Vector)o;
 554         return VectorIntrinsics.binaryOp(
 555             VECTOR_OP_SUB, Long64Vector.class, long.class, LENGTH,
 556             this, v,
 557             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a - b)));
 558     }
 559 
 560     @Override
 561     @ForceInline
 562     public Long64Vector sub(Vector<Long> v, Mask<Long> m) {
 563         return blend(sub(v), m);
 564     }
 565 
 566     @Override
 567     @ForceInline
 568     public Long64Vector mul(Vector<Long> o) {
 569         Objects.requireNonNull(o);
 570         Long64Vector v = (Long64Vector)o;
 571         return VectorIntrinsics.binaryOp(
 572             VECTOR_OP_MUL, Long64Vector.class, long.class, LENGTH,
 573             this, v,
 574             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a * b)));
 575     }
 576 
 577     @Override
 578     @ForceInline
 579     public Long64Vector mul(Vector<Long> v, Mask<Long> m) {
 580         return blend(mul(v), m);
 581     }
 582 
 583     @Override
 584     @ForceInline
 585     public Long64Vector min(Vector<Long> o) {
 586         Objects.requireNonNull(o);
 587         Long64Vector v = (Long64Vector)o;
 588         return (Long64Vector) VectorIntrinsics.binaryOp(
 589             VECTOR_OP_MIN, Long64Vector.class, long.class, LENGTH,
 590             this, v,
 591             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.min(a, b)));
 592     }
 593 
 594     @Override
 595     @ForceInline
 596     public Long64Vector min(Vector<Long> v, Mask<Long> m) {
 597         return blend(min(v), m);
 598     }
 599 
 600     @Override
 601     @ForceInline
 602     public Long64Vector max(Vector<Long> o) {
 603         Objects.requireNonNull(o);
 604         Long64Vector v = (Long64Vector)o;
 605         return VectorIntrinsics.binaryOp(
 606             VECTOR_OP_MAX, Long64Vector.class, long.class, LENGTH,
 607             this, v,
 608             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.max(a, b)));
 609         }
 610 
 611     @Override
 612     @ForceInline
 613     public Long64Vector max(Vector<Long> v, Mask<Long> m) {
 614         return blend(max(v), m);
 615     }
 616 
 617     @Override
 618     @ForceInline
 619     public Long64Vector and(Vector<Long> o) {
 620         Objects.requireNonNull(o);
 621         Long64Vector v = (Long64Vector)o;
 622         return VectorIntrinsics.binaryOp(
 623             VECTOR_OP_AND, Long64Vector.class, long.class, LENGTH,
 624             this, v,
 625             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a & b)));
 626     }
 627 
 628     @Override
 629     @ForceInline
 630     public Long64Vector or(Vector<Long> o) {
 631         Objects.requireNonNull(o);
 632         Long64Vector v = (Long64Vector)o;
 633         return VectorIntrinsics.binaryOp(
 634             VECTOR_OP_OR, Long64Vector.class, long.class, LENGTH,
 635             this, v,
 636             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a | b)));
 637     }
 638 
 639     @Override
 640     @ForceInline
 641     public Long64Vector xor(Vector<Long> o) {
 642         Objects.requireNonNull(o);
 643         Long64Vector v = (Long64Vector)o;
 644         return VectorIntrinsics.binaryOp(
 645             VECTOR_OP_XOR, Long64Vector.class, long.class, LENGTH,
 646             this, v,
 647             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a ^ b)));
 648     }
 649 
 650     @Override
 651     @ForceInline
 652     public Long64Vector and(Vector<Long> v, Mask<Long> m) {
 653         return blend(and(v), m);
 654     }
 655 
 656     @Override
 657     @ForceInline
 658     public Long64Vector or(Vector<Long> v, Mask<Long> m) {
 659         return blend(or(v), m);
 660     }
 661 
 662     @Override
 663     @ForceInline
 664     public Long64Vector xor(Vector<Long> v, Mask<Long> m) {
 665         return blend(xor(v), m);
 666     }
 667 
 668     @Override
 669     @ForceInline
 670     public Long64Vector shiftL(int s) {
 671         return VectorIntrinsics.broadcastInt(
 672             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 673             this, s,
 674             (v, i) -> v.uOp((__, a) -> (long) (a << i)));
 675     }
 676 
 677     @Override
 678     @ForceInline
 679     public Long64Vector shiftL(int s, Mask<Long> m) {
 680         return blend(shiftL(s), m);
 681     }
 682 
 683     @Override
 684     @ForceInline
 685     public Long64Vector shiftR(int s) {
 686         return VectorIntrinsics.broadcastInt(
 687             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 688             this, s,
 689             (v, i) -> v.uOp((__, a) -> (long) (a >>> i)));
 690     }
 691 
 692     @Override
 693     @ForceInline
 694     public Long64Vector shiftR(int s, Mask<Long> m) {
 695         return blend(shiftR(s), m);
 696     }
 697 
 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 
 795     @Override
 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
 878     public void intoArray(long[] a, int ix) {
 879         Objects.requireNonNull(a);
 880         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 881         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 882                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_LONG_BASE_OFFSET,
 883                                this,
 884                                a, ix,
 885                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 886     }
 887 
 888     @Override
 889     @ForceInline
 890     public final void intoArray(long[] a, int ax, Mask<Long> m) {
 891         LongVector oldVal = LongVector.fromArray(SPECIES, a, ax);
 892         LongVector newVal = oldVal.blend(this, m);
 893         newVal.intoArray(a, ax);
 894     }
 895     @Override
 896     @ForceInline
 897     public void intoArray(long[] a, int ix, int[] b, int iy) {
 898         this.intoArray(a, ix + b[iy]);
 899     }
 900 
 901      @Override
 902      @ForceInline
 903      public final void intoArray(long[] a, int ax, Mask<Long> m, int[] b, int iy) {
 904          // @@@ This can result in out of bounds errors for unset mask lanes
 905          LongVector oldVal = LongVector.fromArray(SPECIES, a, ax, b, iy);
 906          LongVector newVal = oldVal.blend(this, m);
 907          newVal.intoArray(a, ax, b, iy);
 908      }
 909 
 910     @Override
 911     @ForceInline
 912     public void intoByteArray(byte[] a, int ix) {
 913         Objects.requireNonNull(a);
 914         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 915         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 916                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 917                                this,
 918                                a, ix,
 919                                (c, idx, v) -> {
 920                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 921                                    LongBuffer tb = bbc.asLongBuffer();
 922                                    v.forEach((i, e) -> tb.put(e));
 923                                });
 924     }
 925 
 926     @Override
 927     @ForceInline
 928     public final void intoByteArray(byte[] a, int ix, Mask<Long> m) {
 929         Long64Vector oldVal = (Long64Vector) LongVector.fromByteArray(SPECIES, a, ix);
 930         Long64Vector newVal = oldVal.blend(this, m);
 931         newVal.intoByteArray(a, ix);
 932     }
 933 
 934     @Override
 935     @ForceInline
 936     public void intoByteBuffer(ByteBuffer bb, int ix) {
 937         if (bb.order() != ByteOrder.nativeOrder()) {
 938             throw new IllegalArgumentException();
 939         }
 940         if (bb.isReadOnly()) {
 941             throw new ReadOnlyBufferException();
 942         }
 943         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 944         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 945                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 946                                this,
 947                                bb, ix,
 948                                (c, idx, v) -> {
 949                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 950                                    LongBuffer tb = bbc.asLongBuffer();
 951                                    v.forEach((i, e) -> tb.put(e));
 952                                });
 953     }
 954 
 955     @Override
 956     @ForceInline
 957     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Long> m) {
 958         Long64Vector oldVal = (Long64Vector) LongVector.fromByteBuffer(SPECIES, bb, ix);
 959         Long64Vector newVal = oldVal.blend(this, m);
 960         newVal.intoByteBuffer(bb, ix);
 961     }
 962 
 963     //
 964 
 965     @Override
 966     public String toString() {
 967         return Arrays.toString(getElements());
 968     }
 969 
 970     @Override
 971     public boolean equals(Object o) {
 972         if (this == o) return true;
 973         if (o == null || this.getClass() != o.getClass()) return false;
 974 
 975         Long64Vector that = (Long64Vector) o;
 976         return this.equal(that).allTrue();
 977     }
 978 
 979     @Override
 980     public int hashCode() {
 981         return Arrays.hashCode(vec);
 982     }
 983 
 984     // Binary test
 985 
 986     @Override
 987     Long64Mask bTest(Vector<Long> o, FBinTest f) {
 988         long[] vec1 = getElements();
 989         long[] vec2 = ((Long64Vector)o).getElements();
 990         boolean[] bits = new boolean[length()];
 991         for (int i = 0; i < length(); i++){
 992             bits[i] = f.apply(i, vec1[i], vec2[i]);
 993         }
 994         return new Long64Mask(bits);
 995     }
 996 
 997     // Comparisons
 998 
 999     @Override
1000     @ForceInline
1001     public Long64Mask equal(Vector<Long> o) {
1002         Objects.requireNonNull(o);
1003         Long64Vector v = (Long64Vector)o;
1004 
1005         return VectorIntrinsics.compare(
1006             BT_eq, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1007             this, v,
1008             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1009     }
1010 
1011     @Override
1012     @ForceInline
1013     public Long64Mask notEqual(Vector<Long> o) {
1014         Objects.requireNonNull(o);
1015         Long64Vector v = (Long64Vector)o;
1016 
1017         return VectorIntrinsics.compare(
1018             BT_ne, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1019             this, v,
1020             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1021     }
1022 
1023     @Override
1024     @ForceInline
1025     public Long64Mask lessThan(Vector<Long> o) {
1026         Objects.requireNonNull(o);
1027         Long64Vector v = (Long64Vector)o;
1028 
1029         return VectorIntrinsics.compare(
1030             BT_lt, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1031             this, v,
1032             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1033     }
1034 
1035     @Override
1036     @ForceInline
1037     public Long64Mask lessThanEq(Vector<Long> o) {
1038         Objects.requireNonNull(o);
1039         Long64Vector v = (Long64Vector)o;
1040 
1041         return VectorIntrinsics.compare(
1042             BT_le, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1043             this, v,
1044             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1045     }
1046 
1047     @Override
1048     @ForceInline
1049     public Long64Mask greaterThan(Vector<Long> o) {
1050         Objects.requireNonNull(o);
1051         Long64Vector v = (Long64Vector)o;
1052 
1053         return (Long64Mask) VectorIntrinsics.compare(
1054             BT_gt, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1055             this, v,
1056             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1057     }
1058 
1059     @Override
1060     @ForceInline
1061     public Long64Mask greaterThanEq(Vector<Long> o) {
1062         Objects.requireNonNull(o);
1063         Long64Vector v = (Long64Vector)o;
1064 
1065         return VectorIntrinsics.compare(
1066             BT_ge, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1067             this, v,
1068             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1069     }
1070 
1071     // Foreach
1072 
1073     @Override
1074     void forEach(FUnCon f) {
1075         long[] vec = getElements();
1076         for (int i = 0; i < length(); i++) {
1077             f.apply(i, vec[i]);
1078         }
1079     }
1080 
1081     @Override
1082     void forEach(Mask<Long> o, FUnCon f) {
1083         boolean[] mbits = ((Long64Mask)o).getBits();
1084         forEach((i, a) -> {
1085             if (mbits[i]) { f.apply(i, a); }
1086         });
1087     }
1088 
1089 
1090     Double64Vector toFP() {
1091         long[] vec = getElements();
1092         double[] res = new double[this.species().length()];
1093         for(int i = 0; i < this.species().length(); i++){
1094             res[i] = Double.longBitsToDouble(vec[i]);
1095         }
1096         return new Double64Vector(res);
1097     }
1098 
1099     @Override
1100     public Long64Vector rotateEL(int j) {
1101         long[] vec = getElements();
1102         long[] res = new long[length()];
1103         for (int i = 0; i < length(); i++){
1104             res[(j + i) % length()] = vec[i];
1105         }
1106         return new Long64Vector(res);
1107     }
1108 
1109     @Override
1110     public Long64Vector rotateER(int j) {
1111         long[] vec = getElements();
1112         long[] res = new long[length()];
1113         for (int i = 0; i < length(); i++){
1114             int z = i - j;
1115             if(j < 0) {
1116                 res[length() + z] = vec[i];
1117             } else {
1118                 res[z] = vec[i];
1119             }
1120         }
1121         return new Long64Vector(res);
1122     }
1123 
1124     @Override
1125     public Long64Vector shiftEL(int j) {
1126         long[] vec = getElements();
1127         long[] res = new long[length()];
1128         for (int i = 0; i < length() - j; i++) {
1129             res[i] = vec[i + j];
1130         }
1131         return new Long64Vector(res);
1132     }
1133 
1134     @Override
1135     public Long64Vector shiftER(int j) {
1136         long[] vec = getElements();
1137         long[] res = new long[length()];
1138         for (int i = 0; i < length() - j; i++){
1139             res[i + j] = vec[i];
1140         }
1141         return new Long64Vector(res);
1142     }
1143 
1144     @Override
1145     @ForceInline
1146     public Long64Vector rearrange(Vector<Long> v,
1147                                   Shuffle<Long> s, Mask<Long> m) {
1148         return this.rearrange(s).blend(v.rearrange(s), m);
1149     }
1150 
1151     @Override
1152     @ForceInline
1153     public Long64Vector rearrange(Shuffle<Long> o1) {
1154         Objects.requireNonNull(o1);
1155         Long64Shuffle s =  (Long64Shuffle)o1;
1156 
1157         return VectorIntrinsics.rearrangeOp(
1158             Long64Vector.class, Long64Shuffle.class, long.class, LENGTH,
1159             this, s,
1160             (v1, s_) -> v1.uOp((i, a) -> {
1161                 int ei = s_.getElement(i);
1162                 return v1.get(ei);
1163             }));
1164     }
1165 
1166     @Override
1167     @ForceInline
1168     public Long64Vector blend(Vector<Long> o1, Mask<Long> o2) {
1169         Objects.requireNonNull(o1);
1170         Objects.requireNonNull(o2);
1171         Long64Vector v = (Long64Vector)o1;
1172         Long64Mask   m = (Long64Mask)o2;
1173 
1174         return VectorIntrinsics.blend(
1175             Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1176             this, v, m,
1177             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1178     }
1179 
1180     // Accessors
1181 
1182     @Override
1183     public long get(int i) {
1184         if (i < 0 || i >= LENGTH) {
1185             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1186         }
1187         return (long) VectorIntrinsics.extract(
1188                                 Long64Vector.class, long.class, LENGTH,
1189                                 this, i,
1190                                 (vec, ix) -> {
1191                                     long[] vecarr = vec.getElements();
1192                                     return (long)vecarr[ix];
1193                                 });
1194     }
1195 
1196     @Override
1197     public Long64Vector with(int i, long e) {
1198         if (i < 0 || i >= LENGTH) {
1199             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1200         }
1201         return VectorIntrinsics.insert(
1202                                 Long64Vector.class, long.class, LENGTH,
1203                                 this, i, (long)e,
1204                                 (v, ix, bits) -> {
1205                                     long[] res = v.getElements().clone();
1206                                     res[ix] = (long)bits;
1207                                     return new Long64Vector(res);
1208                                 });
1209     }
1210 
1211     // Mask
1212 
1213     static final class Long64Mask extends AbstractMask<Long> {
1214         static final Long64Mask TRUE_MASK = new Long64Mask(true);
1215         static final Long64Mask FALSE_MASK = new Long64Mask(false);
1216 
1217         private final boolean[] bits; // Don't access directly, use getBits() instead.
1218 
1219         public Long64Mask(boolean[] bits) {
1220             this(bits, 0);
1221         }
1222 
1223         public Long64Mask(boolean[] bits, int offset) {
1224             boolean[] a = new boolean[species().length()];
1225             for (int i = 0; i < a.length; i++) {
1226                 a[i] = bits[offset + i];
1227             }
1228             this.bits = a;
1229         }
1230 
1231         public Long64Mask(boolean val) {
1232             boolean[] bits = new boolean[species().length()];
1233             Arrays.fill(bits, val);
1234             this.bits = bits;
1235         }
1236 
1237         boolean[] getBits() {
1238             return VectorIntrinsics.maybeRebox(this).bits;
1239         }
1240 
1241         @Override
1242         Long64Mask uOp(MUnOp f) {
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,
1299                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1300         }
1301 
1302         @Override
1303         @ForceInline
1304         public Long64Mask or(Mask<Long> o) {
1305             Objects.requireNonNull(o);
1306             Long64Mask m = (Long64Mask)o;
1307             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Long64Mask.class, long.class, LENGTH,
1308                                              this, m,
1309                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1310         }
1311 
1312         // Reductions
1313 
1314         @Override
1315         @ForceInline
1316         public boolean anyTrue() {
1317             return VectorIntrinsics.test(BT_ne, Long64Mask.class, long.class, LENGTH,
1318                                          this, this,
1319                                          (m, __) -> anyTrueHelper(((Long64Mask)m).getBits()));
1320         }
1321 
1322         @Override
1323         @ForceInline
1324         public boolean allTrue() {
1325             return VectorIntrinsics.test(BT_overflow, Long64Mask.class, long.class, LENGTH,
1326                                          this, LongVector.maskAllTrue(species()),
1327                                          (m, __) -> allTrueHelper(((Long64Mask)m).getBits()));
1328         }
1329     }
1330 
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 }