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         forEach((i, e) -> a[ix + i] = e);
 881     }
 882 
 883     @Override
 884     @ForceInline
 885     public final void intoArray(long[] a, int ax, Mask<Long> m) {
 886         Objects.requireNonNull(a);
 887         forEach(m, (i, e) -> a[ax + i] = e);
 888     }
 889 
 890     @Override
 891     @ForceInline
 892     public void intoArray(long[] a, int ix, int[] b, int iy) {
 893         this.intoArray(a, ix + b[iy]);
 894     }
 895 
 896     @Override
 897     @ForceInline
 898     public final void intoArray(long[] a, int ax, Mask<Long> m, int[] b, int iy) {
 899         Objects.requireNonNull(a);
 900         Objects.requireNonNull(b);
 901         forEach(m, (i, e) -> a[ax + b[iy+i]] = e);
 902     }
 903 
 904     @Override
 905     @ForceInline
 906     public void intoByteArray(byte[] a, int ix) {
 907         Objects.requireNonNull(a);
 908         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 909         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 910                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 911                                this,
 912                                a, ix,
 913                                (c, idx, v) -> {
 914                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 915                                    LongBuffer tb = bbc.asLongBuffer();
 916                                    v.forEach((i, e) -> tb.put(e));
 917                                });
 918     }
 919 
 920     @Override
 921     @ForceInline
 922     public final void intoByteArray(byte[] a, int ix, Mask<Long> m) {
 923         Long64Vector oldVal = (Long64Vector) LongVector.fromByteArray(SPECIES, a, ix);
 924         Long64Vector newVal = oldVal.blend(this, m);
 925         newVal.intoByteArray(a, ix);
 926     }
 927 
 928     @Override
 929     @ForceInline
 930     public void intoByteBuffer(ByteBuffer bb, int ix) {
 931         if (bb.order() != ByteOrder.nativeOrder()) {
 932             throw new IllegalArgumentException();
 933         }
 934         if (bb.isReadOnly()) {
 935             throw new ReadOnlyBufferException();
 936         }
 937         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 938         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 939                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 940                                this,
 941                                bb, ix,
 942                                (c, idx, v) -> {
 943                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 944                                    LongBuffer tb = bbc.asLongBuffer();
 945                                    v.forEach((i, e) -> tb.put(e));
 946                                });
 947     }
 948 
 949     @Override
 950     @ForceInline
 951     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Long> m) {
 952         Long64Vector oldVal = (Long64Vector) LongVector.fromByteBuffer(SPECIES, bb, ix);
 953         Long64Vector newVal = oldVal.blend(this, m);
 954         newVal.intoByteBuffer(bb, ix);
 955     }
 956 
 957     //
 958 
 959     @Override
 960     public String toString() {
 961         return Arrays.toString(getElements());
 962     }
 963 
 964     @Override
 965     public boolean equals(Object o) {
 966         if (this == o) return true;
 967         if (o == null || this.getClass() != o.getClass()) return false;
 968 
 969         Long64Vector that = (Long64Vector) o;
 970         return this.equal(that).allTrue();
 971     }
 972 
 973     @Override
 974     public int hashCode() {
 975         return Arrays.hashCode(vec);
 976     }
 977 
 978     // Binary test
 979 
 980     @Override
 981     Long64Mask bTest(Vector<Long> o, FBinTest f) {
 982         long[] vec1 = getElements();
 983         long[] vec2 = ((Long64Vector)o).getElements();
 984         boolean[] bits = new boolean[length()];
 985         for (int i = 0; i < length(); i++){
 986             bits[i] = f.apply(i, vec1[i], vec2[i]);
 987         }
 988         return new Long64Mask(bits);
 989     }
 990 
 991     // Comparisons
 992 
 993     @Override
 994     @ForceInline
 995     public Long64Mask equal(Vector<Long> o) {
 996         Objects.requireNonNull(o);
 997         Long64Vector v = (Long64Vector)o;
 998 
 999         return VectorIntrinsics.compare(
1000             BT_eq, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1001             this, v,
1002             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1003     }
1004 
1005     @Override
1006     @ForceInline
1007     public Long64Mask notEqual(Vector<Long> o) {
1008         Objects.requireNonNull(o);
1009         Long64Vector v = (Long64Vector)o;
1010 
1011         return VectorIntrinsics.compare(
1012             BT_ne, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1013             this, v,
1014             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1015     }
1016 
1017     @Override
1018     @ForceInline
1019     public Long64Mask lessThan(Vector<Long> o) {
1020         Objects.requireNonNull(o);
1021         Long64Vector v = (Long64Vector)o;
1022 
1023         return VectorIntrinsics.compare(
1024             BT_lt, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1025             this, v,
1026             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1027     }
1028 
1029     @Override
1030     @ForceInline
1031     public Long64Mask lessThanEq(Vector<Long> o) {
1032         Objects.requireNonNull(o);
1033         Long64Vector v = (Long64Vector)o;
1034 
1035         return VectorIntrinsics.compare(
1036             BT_le, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1037             this, v,
1038             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1039     }
1040 
1041     @Override
1042     @ForceInline
1043     public Long64Mask greaterThan(Vector<Long> o) {
1044         Objects.requireNonNull(o);
1045         Long64Vector v = (Long64Vector)o;
1046 
1047         return (Long64Mask) VectorIntrinsics.compare(
1048             BT_gt, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1049             this, v,
1050             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1051     }
1052 
1053     @Override
1054     @ForceInline
1055     public Long64Mask greaterThanEq(Vector<Long> o) {
1056         Objects.requireNonNull(o);
1057         Long64Vector v = (Long64Vector)o;
1058 
1059         return VectorIntrinsics.compare(
1060             BT_ge, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1061             this, v,
1062             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1063     }
1064 
1065     // Foreach
1066 
1067     @Override
1068     void forEach(FUnCon f) {
1069         long[] vec = getElements();
1070         for (int i = 0; i < length(); i++) {
1071             f.apply(i, vec[i]);
1072         }
1073     }
1074 
1075     @Override
1076     void forEach(Mask<Long> o, FUnCon f) {
1077         boolean[] mbits = ((Long64Mask)o).getBits();
1078         forEach((i, a) -> {
1079             if (mbits[i]) { f.apply(i, a); }
1080         });
1081     }
1082 
1083 
1084     Double64Vector toFP() {
1085         long[] vec = getElements();
1086         double[] res = new double[this.species().length()];
1087         for(int i = 0; i < this.species().length(); i++){
1088             res[i] = Double.longBitsToDouble(vec[i]);
1089         }
1090         return new Double64Vector(res);
1091     }
1092 
1093     @Override
1094     public Long64Vector rotateEL(int j) {
1095         long[] vec = getElements();
1096         long[] res = new long[length()];
1097         for (int i = 0; i < length(); i++){
1098             res[(j + i) % length()] = vec[i];
1099         }
1100         return new Long64Vector(res);
1101     }
1102 
1103     @Override
1104     public Long64Vector rotateER(int j) {
1105         long[] vec = getElements();
1106         long[] res = new long[length()];
1107         for (int i = 0; i < length(); i++){
1108             int z = i - j;
1109             if(j < 0) {
1110                 res[length() + z] = vec[i];
1111             } else {
1112                 res[z] = vec[i];
1113             }
1114         }
1115         return new Long64Vector(res);
1116     }
1117 
1118     @Override
1119     public Long64Vector shiftEL(int j) {
1120         long[] vec = getElements();
1121         long[] res = new long[length()];
1122         for (int i = 0; i < length() - j; i++) {
1123             res[i] = vec[i + j];
1124         }
1125         return new Long64Vector(res);
1126     }
1127 
1128     @Override
1129     public Long64Vector shiftER(int j) {
1130         long[] vec = getElements();
1131         long[] res = new long[length()];
1132         for (int i = 0; i < length() - j; i++){
1133             res[i + j] = vec[i];
1134         }
1135         return new Long64Vector(res);
1136     }
1137 
1138     @Override
1139     @ForceInline
1140     public Long64Vector rearrange(Vector<Long> v,
1141                                   Shuffle<Long> s, Mask<Long> m) {
1142         return this.rearrange(s).blend(v.rearrange(s), m);
1143     }
1144 
1145     @Override
1146     @ForceInline
1147     public Long64Vector rearrange(Shuffle<Long> o1) {
1148         Objects.requireNonNull(o1);
1149         Long64Shuffle s =  (Long64Shuffle)o1;
1150 
1151         return VectorIntrinsics.rearrangeOp(
1152             Long64Vector.class, Long64Shuffle.class, long.class, LENGTH,
1153             this, s,
1154             (v1, s_) -> v1.uOp((i, a) -> {
1155                 int ei = s_.getElement(i);
1156                 return v1.get(ei);
1157             }));
1158     }
1159 
1160     @Override
1161     @ForceInline
1162     public Long64Vector blend(Vector<Long> o1, Mask<Long> o2) {
1163         Objects.requireNonNull(o1);
1164         Objects.requireNonNull(o2);
1165         Long64Vector v = (Long64Vector)o1;
1166         Long64Mask   m = (Long64Mask)o2;
1167 
1168         return VectorIntrinsics.blend(
1169             Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1170             this, v, m,
1171             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1172     }
1173 
1174     // Accessors
1175 
1176     @Override
1177     public long get(int i) {
1178         if (i < 0 || i >= LENGTH) {
1179             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1180         }
1181         return (long) VectorIntrinsics.extract(
1182                                 Long64Vector.class, long.class, LENGTH,
1183                                 this, i,
1184                                 (vec, ix) -> {
1185                                     long[] vecarr = vec.getElements();
1186                                     return (long)vecarr[ix];
1187                                 });
1188     }
1189 
1190     @Override
1191     public Long64Vector with(int i, long e) {
1192         if (i < 0 || i >= LENGTH) {
1193             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1194         }
1195         return VectorIntrinsics.insert(
1196                                 Long64Vector.class, long.class, LENGTH,
1197                                 this, i, (long)e,
1198                                 (v, ix, bits) -> {
1199                                     long[] res = v.getElements().clone();
1200                                     res[ix] = (long)bits;
1201                                     return new Long64Vector(res);
1202                                 });
1203     }
1204 
1205     // Mask
1206 
1207     static final class Long64Mask extends AbstractMask<Long> {
1208         static final Long64Mask TRUE_MASK = new Long64Mask(true);
1209         static final Long64Mask FALSE_MASK = new Long64Mask(false);
1210 
1211         private final boolean[] bits; // Don't access directly, use getBits() instead.
1212 
1213         public Long64Mask(boolean[] bits) {
1214             this(bits, 0);
1215         }
1216 
1217         public Long64Mask(boolean[] bits, int offset) {
1218             boolean[] a = new boolean[species().length()];
1219             for (int i = 0; i < a.length; i++) {
1220                 a[i] = bits[offset + i];
1221             }
1222             this.bits = a;
1223         }
1224 
1225         public Long64Mask(boolean val) {
1226             boolean[] bits = new boolean[species().length()];
1227             Arrays.fill(bits, val);
1228             this.bits = bits;
1229         }
1230 
1231         boolean[] getBits() {
1232             return VectorIntrinsics.maybeRebox(this).bits;
1233         }
1234 
1235         @Override
1236         Long64Mask uOp(MUnOp f) {
1237             boolean[] res = new boolean[species().length()];
1238             boolean[] bits = getBits();
1239             for (int i = 0; i < species().length(); i++) {
1240                 res[i] = f.apply(i, bits[i]);
1241             }
1242             return new Long64Mask(res);
1243         }
1244 
1245         @Override
1246         Long64Mask bOp(Mask<Long> o, MBinOp f) {
1247             boolean[] res = new boolean[species().length()];
1248             boolean[] bits = getBits();
1249             boolean[] mbits = ((Long64Mask)o).getBits();
1250             for (int i = 0; i < species().length(); i++) {
1251                 res[i] = f.apply(i, bits[i], mbits[i]);
1252             }
1253             return new Long64Mask(res);
1254         }
1255 
1256         @Override
1257         public Long64Species species() {
1258             return SPECIES;
1259         }
1260 
1261         @Override
1262         public Long64Vector toVector() {
1263             long[] res = new long[species().length()];
1264             boolean[] bits = getBits();
1265             for (int i = 0; i < species().length(); i++) {
1266                 // -1 will result in the most significant bit being set in
1267                 // addition to some or all other bits
1268                 res[i] = (long) (bits[i] ? -1 : 0);
1269             }
1270             return new Long64Vector(res);
1271         }
1272 
1273         // Unary operations
1274 
1275         @Override
1276         @ForceInline
1277         public Long64Mask not() {
1278             return (Long64Mask) VectorIntrinsics.unaryOp(
1279                                              VECTOR_OP_NOT, Long64Mask.class, long.class, LENGTH,
1280                                              this,
1281                                              (m1) -> m1.uOp((i, a) -> !a));
1282         }
1283 
1284         // Binary operations
1285 
1286         @Override
1287         @ForceInline
1288         public Long64Mask and(Mask<Long> o) {
1289             Objects.requireNonNull(o);
1290             Long64Mask m = (Long64Mask)o;
1291             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long64Mask.class, long.class, LENGTH,
1292                                              this, m,
1293                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1294         }
1295 
1296         @Override
1297         @ForceInline
1298         public Long64Mask or(Mask<Long> o) {
1299             Objects.requireNonNull(o);
1300             Long64Mask m = (Long64Mask)o;
1301             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Long64Mask.class, long.class, LENGTH,
1302                                              this, m,
1303                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1304         }
1305 
1306         // Reductions
1307 
1308         @Override
1309         @ForceInline
1310         public boolean anyTrue() {
1311             return VectorIntrinsics.test(BT_ne, Long64Mask.class, long.class, LENGTH,
1312                                          this, this,
1313                                          (m, __) -> anyTrueHelper(((Long64Mask)m).getBits()));
1314         }
1315 
1316         @Override
1317         @ForceInline
1318         public boolean allTrue() {
1319             return VectorIntrinsics.test(BT_overflow, Long64Mask.class, long.class, LENGTH,
1320                                          this, LongVector.maskAllTrue(species()),
1321                                          (m, __) -> allTrueHelper(((Long64Mask)m).getBits()));
1322         }
1323     }
1324 
1325     // Shuffle
1326 
1327     static final class Long64Shuffle extends AbstractShuffle<Long> {
1328         Long64Shuffle(byte[] reorder) {
1329             super(reorder);
1330         }
1331 
1332         public Long64Shuffle(int[] reorder) {
1333             super(reorder);
1334         }
1335 
1336         public Long64Shuffle(int[] reorder, int i) {
1337             super(reorder, i);
1338         }
1339 
1340         public Long64Shuffle(IntUnaryOperator f) {
1341             super(f);
1342         }
1343 
1344         @Override
1345         public Long64Species species() {
1346             return SPECIES;
1347         }
1348 
1349         @Override
1350         public LongVector toVector() {
1351             long[] va = new long[SPECIES.length()];
1352             for (int i = 0; i < va.length; i++) {
1353               va[i] = (long) getElement(i);
1354             }
1355             return LongVector.fromArray(SPECIES, va, 0);
1356         }
1357 
1358         @Override
1359         public Long64Shuffle rearrange(Vector.Shuffle<Long> o) {
1360             Long64Shuffle s = (Long64Shuffle) o;
1361             byte[] r = new byte[reorder.length];
1362             for (int i = 0; i < reorder.length; i++) {
1363                 r[i] = reorder[s.reorder[i]];
1364             }
1365             return new Long64Shuffle(r);
1366         }
1367     }
1368 
1369     // Species
1370 
1371     @Override
1372     public Long64Species species() {
1373         return SPECIES;
1374     }
1375 
1376     static final class Long64Species extends LongSpecies {
1377         static final int BIT_SIZE = Shape.S_64_BIT.bitSize();
1378 
1379         static final int LENGTH = BIT_SIZE / Long.SIZE;
1380 
1381         @Override
1382         public String toString() {
1383            StringBuilder sb = new StringBuilder("Shape[");
1384            sb.append(bitSize()).append(" bits, ");
1385            sb.append(length()).append(" ").append(long.class.getSimpleName()).append("s x ");
1386            sb.append(elementSize()).append(" bits");
1387            sb.append("]");
1388            return sb.toString();
1389         }
1390 
1391         @Override
1392         @ForceInline
1393         public int bitSize() {
1394             return BIT_SIZE;
1395         }
1396 
1397         @Override
1398         @ForceInline
1399         public int length() {
1400             return LENGTH;
1401         }
1402 
1403         @Override
1404         @ForceInline
1405         public Class<Long> elementType() {
1406             return long.class;
1407         }
1408 
1409         @Override
1410         @ForceInline
1411         public Class<?> boxType() {
1412             return Long64Vector.class;
1413         }
1414 
1415         @Override
1416         @ForceInline
1417         public Class<?> maskType() {
1418             return Long64Mask.class;
1419         }
1420 
1421         @Override
1422         @ForceInline
1423         public int elementSize() {
1424             return Long.SIZE;
1425         }
1426 
1427         @Override
1428         @ForceInline
1429         @SuppressWarnings("unchecked")
1430         Class<?> vectorType() {
1431             return Long64Vector.class;
1432         }
1433 
1434         @Override
1435         @ForceInline
1436         public Shape shape() {
1437             return Shape.S_64_BIT;
1438         }
1439 
1440        @Override
1441        IntVector.IntSpecies indexSpecies() {
1442           return INDEX_SPEC;
1443        }
1444 
1445         @Override
1446         Long64Vector op(FOp f) {
1447             long[] res = new long[length()];
1448             for (int i = 0; i < length(); i++) {
1449                 res[i] = f.apply(i);
1450             }
1451             return new Long64Vector(res);
1452         }
1453 
1454         @Override
1455         Long64Vector op(Mask<Long> o, FOp f) {
1456             long[] res = new long[length()];
1457             boolean[] mbits = ((Long64Mask)o).getBits();
1458             for (int i = 0; i < length(); i++) {
1459                 if (mbits[i]) {
1460                     res[i] = f.apply(i);
1461                 }
1462             }
1463             return new Long64Vector(res);
1464         }
1465 
1466         @Override
1467         Long64Mask opm(FOpm f) {
1468             boolean[] res = new boolean[length()];
1469             for (int i = 0; i < length(); i++) {
1470                 res[i] = (boolean)f.apply(i);
1471             }
1472             return new Long64Mask(res);
1473         }
1474 
1475         // Factories
1476 
1477         @Override
1478         @ForceInline
1479         public Long64Vector zero() {
1480             return VectorIntrinsics.broadcastCoerced(Long64Vector.class, long.class, LENGTH,
1481                                                      0, SPECIES,
1482                                                      ((bits, s) -> ((Long64Species)s).op(i -> (long)bits)));
1483         }
1484 
1485         @Override
1486         @ForceInline
1487         public Long64Vector broadcast(long e) {
1488             return VectorIntrinsics.broadcastCoerced(
1489                 Long64Vector.class, long.class, LENGTH,
1490                 e, SPECIES,
1491                 ((bits, s) -> ((Long64Species)s).op(i -> (long)bits)));
1492         }
1493 
1494         @Override
1495         @ForceInline
1496         public Long64Vector scalars(long... es) {
1497             Objects.requireNonNull(es);
1498             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1499             return VectorIntrinsics.load(Long64Vector.class, long.class, LENGTH,
1500                                          es, Unsafe.ARRAY_LONG_BASE_OFFSET,
1501                                          es, ix, SPECIES,
1502                                          (c, idx, s) -> ((Long64Species)s).op(n -> c[idx + n]));
1503         }
1504 
1505         @Override
1506         @ForceInline
1507         public <E> Long64Mask cast(Mask<E> m) {
1508             if (m.length() != LENGTH)
1509                 throw new IllegalArgumentException("Mask length this species length differ");
1510             return new Long64Mask(m.toArray());
1511         }
1512 
1513         @Override
1514         @ForceInline
1515         public <E> Long64Shuffle cast(Shuffle<E> s) {
1516             if (s.length() != LENGTH)
1517                 throw new IllegalArgumentException("Shuffle length this species length differ");
1518             return new Long64Shuffle(s.toArray());
1519         }
1520     }
1521 }