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     private static final VectorSpecies<Long> SPECIES = LongVector.SPECIES_64;
  42 
  43     static final Long64Vector ZERO = new Long64Vector();
  44 
  45     static final int LENGTH = SPECIES.length();
  46 
  47     // Index vector species
  48     private static final IntVector.IntSpecies INDEX_SPECIES;
  49 
  50     static {
  51         INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(VectorShape.S_64_BIT);
  52     }
  53 
  54     private final long[] vec; // Don't access directly, use getElements() instead.
  55 
  56     private long[] getElements() {
  57         return VectorIntrinsics.maybeRebox(this).vec;
  58     }
  59 
  60     Long64Vector() {
  61         vec = new long[SPECIES.length()];
  62     }
  63 
  64     Long64Vector(long[] v) {
  65         vec = v;
  66     }
  67 
  68     @Override
  69     public int length() { return LENGTH; }
  70 
  71     // Unary operator
  72 
  73     @Override
  74     Long64Vector uOp(FUnOp f) {
  75         long[] vec = getElements();
  76         long[] res = new long[length()];
  77         for (int i = 0; i < length(); i++) {
  78             res[i] = f.apply(i, vec[i]);
  79         }
  80         return new Long64Vector(res);
  81     }
  82 
  83     @Override
  84     Long64Vector uOp(VectorMask<Long> o, FUnOp f) {
  85         long[] vec = getElements();
  86         long[] res = new long[length()];
  87         boolean[] mbits = ((Long64Mask)o).getBits();
  88         for (int i = 0; i < length(); i++) {
  89             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
  90         }
  91         return new Long64Vector(res);
  92     }
  93 
  94     // Binary operator
  95 
  96     @Override
  97     Long64Vector bOp(Vector<Long> o, FBinOp f) {
  98         long[] res = new long[length()];
  99         long[] vec1 = this.getElements();
 100         long[] vec2 = ((Long64Vector)o).getElements();
 101         for (int i = 0; i < length(); i++) {
 102             res[i] = f.apply(i, vec1[i], vec2[i]);
 103         }
 104         return new Long64Vector(res);
 105     }
 106 
 107     @Override
 108     Long64Vector bOp(Vector<Long> o1, VectorMask<Long> o2, FBinOp f) {
 109         long[] res = new long[length()];
 110         long[] vec1 = this.getElements();
 111         long[] vec2 = ((Long64Vector)o1).getElements();
 112         boolean[] mbits = ((Long64Mask)o2).getBits();
 113         for (int i = 0; i < length(); i++) {
 114             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
 115         }
 116         return new Long64Vector(res);
 117     }
 118 
 119     // Trinary operator
 120 
 121     @Override
 122     Long64Vector tOp(Vector<Long> o1, Vector<Long> o2, FTriOp f) {
 123         long[] res = new long[length()];
 124         long[] vec1 = this.getElements();
 125         long[] vec2 = ((Long64Vector)o1).getElements();
 126         long[] vec3 = ((Long64Vector)o2).getElements();
 127         for (int i = 0; i < length(); i++) {
 128             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
 129         }
 130         return new Long64Vector(res);
 131     }
 132 
 133     @Override
 134     Long64Vector tOp(Vector<Long> o1, Vector<Long> o2, VectorMask<Long> o3, FTriOp f) {
 135         long[] res = new long[length()];
 136         long[] vec1 = getElements();
 137         long[] vec2 = ((Long64Vector)o1).getElements();
 138         long[] vec3 = ((Long64Vector)o2).getElements();
 139         boolean[] mbits = ((Long64Mask)o3).getBits();
 140         for (int i = 0; i < length(); i++) {
 141             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
 142         }
 143         return new Long64Vector(res);
 144     }
 145 
 146     @Override
 147     long rOp(long v, FBinOp f) {
 148         long[] vec = getElements();
 149         for (int i = 0; i < length(); i++) {
 150             v = f.apply(i, v, vec[i]);
 151         }
 152         return v;
 153     }
 154 
 155     @Override
 156     @ForceInline
 157     public <F> Vector<F> cast(VectorSpecies<F> s) {
 158         Objects.requireNonNull(s);
 159         if (s.length() != LENGTH)
 160             throw new IllegalArgumentException("Vector length this species length differ");
 161 
 162         return VectorIntrinsics.cast(
 163             Long64Vector.class,
 164             long.class, LENGTH,
 165             s.boxType(),
 166             s.elementType(), LENGTH,
 167             this, s,
 168             (species, vector) -> vector.castDefault(species)
 169         );
 170     }
 171 
 172     @SuppressWarnings("unchecked")
 173     @ForceInline
 174     private <F> Vector<F> castDefault(VectorSpecies<F> s) {
 175         int limit = s.length();
 176 
 177         Class<?> stype = s.elementType();
 178         if (stype == byte.class) {
 179             byte[] a = new byte[limit];
 180             for (int i = 0; i < limit; i++) {
 181                 a[i] = (byte) this.get(i);
 182             }
 183             return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
 184         } else if (stype == short.class) {
 185             short[] a = new short[limit];
 186             for (int i = 0; i < limit; i++) {
 187                 a[i] = (short) this.get(i);
 188             }
 189             return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
 190         } else if (stype == int.class) {
 191             int[] a = new int[limit];
 192             for (int i = 0; i < limit; i++) {
 193                 a[i] = (int) this.get(i);
 194             }
 195             return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
 196         } else if (stype == long.class) {
 197             long[] a = new long[limit];
 198             for (int i = 0; i < limit; i++) {
 199                 a[i] = (long) this.get(i);
 200             }
 201             return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
 202         } else if (stype == float.class) {
 203             float[] a = new float[limit];
 204             for (int i = 0; i < limit; i++) {
 205                 a[i] = (float) this.get(i);
 206             }
 207             return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
 208         } else if (stype == double.class) {
 209             double[] a = new double[limit];
 210             for (int i = 0; i < limit; i++) {
 211                 a[i] = (double) this.get(i);
 212             }
 213             return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
 214         } else {
 215             throw new UnsupportedOperationException("Bad lane type for casting.");
 216         }
 217     }
 218 
 219     @Override
 220     @ForceInline
 221     @SuppressWarnings("unchecked")
 222     public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
 223         Objects.requireNonNull(s);
 224 
 225         if(s.elementType().equals(long.class)) {
 226             return (Vector<F>) reshape((VectorSpecies<Long>)s);
 227         }
 228         if(s.bitSize() == bitSize()) {
 229             return reinterpretType(s);
 230         }
 231 
 232         return defaultReinterpret(s);
 233     }
 234 
 235     @ForceInline
 236     private <F> Vector<F> reinterpretType(VectorSpecies<F> s) {
 237         Objects.requireNonNull(s);
 238 
 239         Class<?> stype = s.elementType();
 240         if (stype == byte.class) {
 241             return VectorIntrinsics.reinterpret(
 242                 Long64Vector.class,
 243                 long.class, LENGTH,
 244                 Byte64Vector.class,
 245                 byte.class, Byte64Vector.LENGTH,
 246                 this, s,
 247                 (species, vector) -> vector.defaultReinterpret(species)
 248             );
 249         } else if (stype == short.class) {
 250             return VectorIntrinsics.reinterpret(
 251                 Long64Vector.class,
 252                 long.class, LENGTH,
 253                 Short64Vector.class,
 254                 short.class, Short64Vector.LENGTH,
 255                 this, s,
 256                 (species, vector) -> vector.defaultReinterpret(species)
 257             );
 258         } else if (stype == int.class) {
 259             return VectorIntrinsics.reinterpret(
 260                 Long64Vector.class,
 261                 long.class, LENGTH,
 262                 Int64Vector.class,
 263                 int.class, Int64Vector.LENGTH,
 264                 this, s,
 265                 (species, vector) -> vector.defaultReinterpret(species)
 266             );
 267         } else if (stype == long.class) {
 268             return VectorIntrinsics.reinterpret(
 269                 Long64Vector.class,
 270                 long.class, LENGTH,
 271                 Long64Vector.class,
 272                 long.class, Long64Vector.LENGTH,
 273                 this, s,
 274                 (species, vector) -> vector.defaultReinterpret(species)
 275             );
 276         } else if (stype == float.class) {
 277             return VectorIntrinsics.reinterpret(
 278                 Long64Vector.class,
 279                 long.class, LENGTH,
 280                 Float64Vector.class,
 281                 float.class, Float64Vector.LENGTH,
 282                 this, s,
 283                 (species, vector) -> vector.defaultReinterpret(species)
 284             );
 285         } else if (stype == double.class) {
 286             return VectorIntrinsics.reinterpret(
 287                 Long64Vector.class,
 288                 long.class, LENGTH,
 289                 Double64Vector.class,
 290                 double.class, Double64Vector.LENGTH,
 291                 this, s,
 292                 (species, vector) -> vector.defaultReinterpret(species)
 293             );
 294         } else {
 295             throw new UnsupportedOperationException("Bad lane type for casting.");
 296         }
 297     }
 298 
 299     @Override
 300     @ForceInline
 301     public LongVector reshape(VectorSpecies<Long> s) {
 302         Objects.requireNonNull(s);
 303         if (s.bitSize() == 64 && (s.boxType() == Long64Vector.class)) {
 304             return VectorIntrinsics.reinterpret(
 305                 Long64Vector.class,
 306                 long.class, LENGTH,
 307                 Long64Vector.class,
 308                 long.class, Long64Vector.LENGTH,
 309                 this, s,
 310                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 311             );
 312         } else if (s.bitSize() == 128 && (s.boxType() == Long128Vector.class)) {
 313             return VectorIntrinsics.reinterpret(
 314                 Long64Vector.class,
 315                 long.class, LENGTH,
 316                 Long128Vector.class,
 317                 long.class, Long128Vector.LENGTH,
 318                 this, s,
 319                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 320             );
 321         } else if (s.bitSize() == 256 && (s.boxType() == Long256Vector.class)) {
 322             return VectorIntrinsics.reinterpret(
 323                 Long64Vector.class,
 324                 long.class, LENGTH,
 325                 Long256Vector.class,
 326                 long.class, Long256Vector.LENGTH,
 327                 this, s,
 328                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 329             );
 330         } else if (s.bitSize() == 512 && (s.boxType() == Long512Vector.class)) {
 331             return VectorIntrinsics.reinterpret(
 332                 Long64Vector.class,
 333                 long.class, LENGTH,
 334                 Long512Vector.class,
 335                 long.class, Long512Vector.LENGTH,
 336                 this, s,
 337                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 338             );
 339         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 340                 && (s.bitSize() % 128 == 0) && (s.boxType() == LongMaxVector.class)) {
 341             return VectorIntrinsics.reinterpret(
 342                 Long64Vector.class,
 343                 long.class, LENGTH,
 344                 LongMaxVector.class,
 345                 long.class, LongMaxVector.LENGTH,
 346                 this, s,
 347                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 348             );
 349         } else {
 350             throw new InternalError("Unimplemented size");
 351         }
 352     }
 353 
 354     // Binary operations with scalars
 355 
 356     @Override
 357     @ForceInline
 358     public LongVector add(long o) {
 359         return add((Long64Vector)LongVector.broadcast(SPECIES, o));
 360     }
 361 
 362     @Override
 363     @ForceInline
 364     public LongVector add(long o, VectorMask<Long> m) {
 365         return add((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 366     }
 367 
 368     @Override
 369     @ForceInline
 370     public LongVector sub(long o) {
 371         return sub((Long64Vector)LongVector.broadcast(SPECIES, o));
 372     }
 373 
 374     @Override
 375     @ForceInline
 376     public LongVector sub(long o, VectorMask<Long> m) {
 377         return sub((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 378     }
 379 
 380     @Override
 381     @ForceInline
 382     public LongVector mul(long o) {
 383         return mul((Long64Vector)LongVector.broadcast(SPECIES, o));
 384     }
 385 
 386     @Override
 387     @ForceInline
 388     public LongVector mul(long o, VectorMask<Long> m) {
 389         return mul((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 390     }
 391 
 392     @Override
 393     @ForceInline
 394     public LongVector min(long o) {
 395         return min((Long64Vector)LongVector.broadcast(SPECIES, o));
 396     }
 397 
 398     @Override
 399     @ForceInline
 400     public LongVector max(long o) {
 401         return max((Long64Vector)LongVector.broadcast(SPECIES, o));
 402     }
 403 
 404     @Override
 405     @ForceInline
 406     public VectorMask<Long> equal(long o) {
 407         return equal((Long64Vector)LongVector.broadcast(SPECIES, o));
 408     }
 409 
 410     @Override
 411     @ForceInline
 412     public VectorMask<Long> notEqual(long o) {
 413         return notEqual((Long64Vector)LongVector.broadcast(SPECIES, o));
 414     }
 415 
 416     @Override
 417     @ForceInline
 418     public VectorMask<Long> lessThan(long o) {
 419         return lessThan((Long64Vector)LongVector.broadcast(SPECIES, o));
 420     }
 421 
 422     @Override
 423     @ForceInline
 424     public VectorMask<Long> lessThanEq(long o) {
 425         return lessThanEq((Long64Vector)LongVector.broadcast(SPECIES, o));
 426     }
 427 
 428     @Override
 429     @ForceInline
 430     public VectorMask<Long> greaterThan(long o) {
 431         return greaterThan((Long64Vector)LongVector.broadcast(SPECIES, o));
 432     }
 433 
 434     @Override
 435     @ForceInline
 436     public VectorMask<Long> greaterThanEq(long o) {
 437         return greaterThanEq((Long64Vector)LongVector.broadcast(SPECIES, o));
 438     }
 439 
 440     @Override
 441     @ForceInline
 442     public LongVector blend(long o, VectorMask<Long> m) {
 443         return blend((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 444     }
 445 
 446 
 447     @Override
 448     @ForceInline
 449     public LongVector and(long o) {
 450         return and((Long64Vector)LongVector.broadcast(SPECIES, o));
 451     }
 452 
 453     @Override
 454     @ForceInline
 455     public LongVector and(long o, VectorMask<Long> m) {
 456         return and((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 457     }
 458 
 459     @Override
 460     @ForceInline
 461     public LongVector or(long o) {
 462         return or((Long64Vector)LongVector.broadcast(SPECIES, o));
 463     }
 464 
 465     @Override
 466     @ForceInline
 467     public LongVector or(long o, VectorMask<Long> m) {
 468         return or((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 469     }
 470 
 471     @Override
 472     @ForceInline
 473     public LongVector xor(long o) {
 474         return xor((Long64Vector)LongVector.broadcast(SPECIES, o));
 475     }
 476 
 477     @Override
 478     @ForceInline
 479     public LongVector xor(long o, VectorMask<Long> m) {
 480         return xor((Long64Vector)LongVector.broadcast(SPECIES, o), m);
 481     }
 482 
 483     @Override
 484     @ForceInline
 485     public Long64Vector neg() {
 486         return (Long64Vector)zero(SPECIES).sub(this);
 487     }
 488 
 489     // Unary operations
 490 
 491     @ForceInline
 492     @Override
 493     public Long64Vector neg(VectorMask<Long> m) {
 494         return blend(neg(), m);
 495     }
 496 
 497     @Override
 498     @ForceInline
 499     public Long64Vector abs() {
 500         return VectorIntrinsics.unaryOp(
 501             VECTOR_OP_ABS, Long64Vector.class, long.class, LENGTH,
 502             this,
 503             v1 -> v1.uOp((i, a) -> (long) Math.abs(a)));
 504     }
 505 
 506     @ForceInline
 507     @Override
 508     public Long64Vector abs(VectorMask<Long> m) {
 509         return blend(abs(), m);
 510     }
 511 
 512 
 513     @Override
 514     @ForceInline
 515     public Long64Vector not() {
 516         return VectorIntrinsics.unaryOp(
 517             VECTOR_OP_NOT, Long64Vector.class, long.class, LENGTH,
 518             this,
 519             v1 -> v1.uOp((i, a) -> (long) ~a));
 520     }
 521 
 522     @ForceInline
 523     @Override
 524     public Long64Vector not(VectorMask<Long> m) {
 525         return blend(not(), m);
 526     }
 527     // Binary operations
 528 
 529     @Override
 530     @ForceInline
 531     public Long64Vector add(Vector<Long> o) {
 532         Objects.requireNonNull(o);
 533         Long64Vector v = (Long64Vector)o;
 534         return VectorIntrinsics.binaryOp(
 535             VECTOR_OP_ADD, Long64Vector.class, long.class, LENGTH,
 536             this, v,
 537             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a + b)));
 538     }
 539 
 540     @Override
 541     @ForceInline
 542     public Long64Vector add(Vector<Long> v, VectorMask<Long> m) {
 543         return blend(add(v), m);
 544     }
 545 
 546     @Override
 547     @ForceInline
 548     public Long64Vector sub(Vector<Long> o) {
 549         Objects.requireNonNull(o);
 550         Long64Vector v = (Long64Vector)o;
 551         return VectorIntrinsics.binaryOp(
 552             VECTOR_OP_SUB, Long64Vector.class, long.class, LENGTH,
 553             this, v,
 554             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a - b)));
 555     }
 556 
 557     @Override
 558     @ForceInline
 559     public Long64Vector sub(Vector<Long> v, VectorMask<Long> m) {
 560         return blend(sub(v), m);
 561     }
 562 
 563     @Override
 564     @ForceInline
 565     public Long64Vector mul(Vector<Long> o) {
 566         Objects.requireNonNull(o);
 567         Long64Vector v = (Long64Vector)o;
 568         return VectorIntrinsics.binaryOp(
 569             VECTOR_OP_MUL, Long64Vector.class, long.class, LENGTH,
 570             this, v,
 571             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a * b)));
 572     }
 573 
 574     @Override
 575     @ForceInline
 576     public Long64Vector mul(Vector<Long> v, VectorMask<Long> m) {
 577         return blend(mul(v), m);
 578     }
 579 
 580     @Override
 581     @ForceInline
 582     public Long64Vector min(Vector<Long> o) {
 583         Objects.requireNonNull(o);
 584         Long64Vector v = (Long64Vector)o;
 585         return (Long64Vector) VectorIntrinsics.binaryOp(
 586             VECTOR_OP_MIN, Long64Vector.class, long.class, LENGTH,
 587             this, v,
 588             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.min(a, b)));
 589     }
 590 
 591     @Override
 592     @ForceInline
 593     public Long64Vector min(Vector<Long> v, VectorMask<Long> m) {
 594         return blend(min(v), m);
 595     }
 596 
 597     @Override
 598     @ForceInline
 599     public Long64Vector max(Vector<Long> o) {
 600         Objects.requireNonNull(o);
 601         Long64Vector v = (Long64Vector)o;
 602         return VectorIntrinsics.binaryOp(
 603             VECTOR_OP_MAX, Long64Vector.class, long.class, LENGTH,
 604             this, v,
 605             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.max(a, b)));
 606         }
 607 
 608     @Override
 609     @ForceInline
 610     public Long64Vector max(Vector<Long> v, VectorMask<Long> m) {
 611         return blend(max(v), m);
 612     }
 613 
 614     @Override
 615     @ForceInline
 616     public Long64Vector and(Vector<Long> o) {
 617         Objects.requireNonNull(o);
 618         Long64Vector v = (Long64Vector)o;
 619         return VectorIntrinsics.binaryOp(
 620             VECTOR_OP_AND, Long64Vector.class, long.class, LENGTH,
 621             this, v,
 622             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a & b)));
 623     }
 624 
 625     @Override
 626     @ForceInline
 627     public Long64Vector or(Vector<Long> o) {
 628         Objects.requireNonNull(o);
 629         Long64Vector v = (Long64Vector)o;
 630         return VectorIntrinsics.binaryOp(
 631             VECTOR_OP_OR, Long64Vector.class, long.class, LENGTH,
 632             this, v,
 633             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a | b)));
 634     }
 635 
 636     @Override
 637     @ForceInline
 638     public Long64Vector xor(Vector<Long> o) {
 639         Objects.requireNonNull(o);
 640         Long64Vector v = (Long64Vector)o;
 641         return VectorIntrinsics.binaryOp(
 642             VECTOR_OP_XOR, Long64Vector.class, long.class, LENGTH,
 643             this, v,
 644             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a ^ b)));
 645     }
 646 
 647     @Override
 648     @ForceInline
 649     public Long64Vector and(Vector<Long> v, VectorMask<Long> m) {
 650         return blend(and(v), m);
 651     }
 652 
 653     @Override
 654     @ForceInline
 655     public Long64Vector or(Vector<Long> v, VectorMask<Long> m) {
 656         return blend(or(v), m);
 657     }
 658 
 659     @Override
 660     @ForceInline
 661     public Long64Vector xor(Vector<Long> v, VectorMask<Long> m) {
 662         return blend(xor(v), m);
 663     }
 664 
 665     @Override
 666     @ForceInline
 667     public Long64Vector shiftL(int s) {
 668         return VectorIntrinsics.broadcastInt(
 669             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 670             this, s,
 671             (v, i) -> v.uOp((__, a) -> (long) (a << i)));
 672     }
 673 
 674     @Override
 675     @ForceInline
 676     public Long64Vector shiftL(int s, VectorMask<Long> m) {
 677         return blend(shiftL(s), m);
 678     }
 679 
 680     @Override
 681     @ForceInline
 682     public Long64Vector shiftR(int s) {
 683         return VectorIntrinsics.broadcastInt(
 684             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 685             this, s,
 686             (v, i) -> v.uOp((__, a) -> (long) (a >>> i)));
 687     }
 688 
 689     @Override
 690     @ForceInline
 691     public Long64Vector shiftR(int s, VectorMask<Long> m) {
 692         return blend(shiftR(s), m);
 693     }
 694 
 695     @Override
 696     @ForceInline
 697     public Long64Vector aShiftR(int s) {
 698         return VectorIntrinsics.broadcastInt(
 699             VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
 700             this, s,
 701             (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
 702     }
 703 
 704     @Override
 705     @ForceInline
 706     public Long64Vector aShiftR(int s, VectorMask<Long> m) {
 707         return blend(aShiftR(s), m);
 708     }
 709 
 710     @Override
 711     @ForceInline
 712     public Long64Vector shiftL(Vector<Long> s) {
 713         Long64Vector shiftv = (Long64Vector)s;
 714         // As per shift specification for Java, mask the shift count.
 715         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 716         return VectorIntrinsics.binaryOp(
 717             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 718             this, shiftv,
 719             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
 720     }
 721 
 722     @Override
 723     @ForceInline
 724     public Long64Vector shiftR(Vector<Long> s) {
 725         Long64Vector shiftv = (Long64Vector)s;
 726         // As per shift specification for Java, mask the shift count.
 727         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 728         return VectorIntrinsics.binaryOp(
 729             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 730             this, shiftv,
 731             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >>> b)));
 732     }
 733 
 734     @Override
 735     @ForceInline
 736     public Long64Vector aShiftR(Vector<Long> s) {
 737         Long64Vector shiftv = (Long64Vector)s;
 738         // As per shift specification for Java, mask the shift count.
 739         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 740         return VectorIntrinsics.binaryOp(
 741             VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
 742             this, shiftv,
 743             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >> b)));
 744     }
 745     // Ternary operations
 746 
 747 
 748     // Type specific horizontal reductions
 749 
 750     @Override
 751     @ForceInline
 752     public long addAll() {
 753         return (long) VectorIntrinsics.reductionCoerced(
 754             VECTOR_OP_ADD, Long64Vector.class, long.class, LENGTH,
 755             this,
 756             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a + b)));
 757     }
 758 
 759     @Override
 760     @ForceInline
 761     public long andAll() {
 762         return (long) VectorIntrinsics.reductionCoerced(
 763             VECTOR_OP_AND, Long64Vector.class, long.class, LENGTH,
 764             this,
 765             v -> (long) v.rOp((long) -1, (i, a, b) -> (long) (a & b)));
 766     }
 767 
 768     @Override
 769     @ForceInline
 770     public long andAll(VectorMask<Long> m) {
 771         return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) -1), m).andAll();
 772     }
 773 
 774     @Override
 775     @ForceInline
 776     public long minAll() {
 777         return (long) VectorIntrinsics.reductionCoerced(
 778             VECTOR_OP_MIN, Long64Vector.class, long.class, LENGTH,
 779             this,
 780             v -> (long) v.rOp(Long.MAX_VALUE , (i, a, b) -> (long) Math.min(a, b)));
 781     }
 782 
 783     @Override
 784     @ForceInline
 785     public long maxAll() {
 786         return (long) VectorIntrinsics.reductionCoerced(
 787             VECTOR_OP_MAX, Long64Vector.class, long.class, LENGTH,
 788             this,
 789             v -> (long) v.rOp(Long.MIN_VALUE , (i, a, b) -> (long) Math.max(a, b)));
 790     }
 791 
 792     @Override
 793     @ForceInline
 794     public long mulAll() {
 795         return (long) VectorIntrinsics.reductionCoerced(
 796             VECTOR_OP_MUL, Long64Vector.class, long.class, LENGTH,
 797             this,
 798             v -> (long) v.rOp((long) 1, (i, a, b) -> (long) (a * b)));
 799     }
 800 
 801     @Override
 802     @ForceInline
 803     public long orAll() {
 804         return (long) VectorIntrinsics.reductionCoerced(
 805             VECTOR_OP_OR, Long64Vector.class, long.class, LENGTH,
 806             this,
 807             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a | b)));
 808     }
 809 
 810     @Override
 811     @ForceInline
 812     public long orAll(VectorMask<Long> m) {
 813         return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 0), m).orAll();
 814     }
 815 
 816     @Override
 817     @ForceInline
 818     public long xorAll() {
 819         return (long) VectorIntrinsics.reductionCoerced(
 820             VECTOR_OP_XOR, Long64Vector.class, long.class, LENGTH,
 821             this,
 822             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a ^ b)));
 823     }
 824 
 825     @Override
 826     @ForceInline
 827     public long xorAll(VectorMask<Long> m) {
 828         return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 0), m).xorAll();
 829     }
 830 
 831 
 832     @Override
 833     @ForceInline
 834     public long addAll(VectorMask<Long> m) {
 835         return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 0), m).addAll();
 836     }
 837 
 838 
 839     @Override
 840     @ForceInline
 841     public long mulAll(VectorMask<Long> m) {
 842         return blend((Long64Vector)LongVector.broadcast(SPECIES, (long) 1), m).mulAll();
 843     }
 844 
 845     @Override
 846     @ForceInline
 847     public long minAll(VectorMask<Long> m) {
 848         return blend((Long64Vector)LongVector.broadcast(SPECIES, Long.MAX_VALUE), m).minAll();
 849     }
 850 
 851     @Override
 852     @ForceInline
 853     public long maxAll(VectorMask<Long> m) {
 854         return blend((Long64Vector)LongVector.broadcast(SPECIES, Long.MIN_VALUE), m).maxAll();
 855     }
 856 
 857     @Override
 858     @ForceInline
 859     public VectorShuffle<Long> toShuffle() {
 860         long[] a = toArray();
 861         int[] sa = new int[a.length];
 862         for (int i = 0; i < a.length; i++) {
 863             sa[i] = (int) a[i];
 864         }
 865         return VectorShuffle.fromArray(SPECIES, sa, 0);
 866     }
 867 
 868     // Memory operations
 869 
 870     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_LONG_INDEX_SCALE);
 871     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 872 
 873     @Override
 874     @ForceInline
 875     public void intoArray(long[] a, int ix) {
 876         Objects.requireNonNull(a);
 877         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 878         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 879                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_LONG_BASE_OFFSET,
 880                                this,
 881                                a, ix,
 882                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 883     }
 884 
 885     @Override
 886     @ForceInline
 887     public final void intoArray(long[] a, int ax, VectorMask<Long> m) {
 888         LongVector oldVal = LongVector.fromArray(SPECIES, a, ax);
 889         LongVector newVal = oldVal.blend(this, m);
 890         newVal.intoArray(a, ax);
 891     }
 892     @Override
 893     @ForceInline
 894     public void intoArray(long[] a, int ix, int[] b, int iy) {
 895         this.intoArray(a, ix + b[iy]);
 896     }
 897 
 898      @Override
 899      @ForceInline
 900      public final void intoArray(long[] a, int ax, VectorMask<Long> m, int[] b, int iy) {
 901          // @@@ This can result in out of bounds errors for unset mask lanes
 902          LongVector oldVal = LongVector.fromArray(SPECIES, a, ax, b, iy);
 903          LongVector newVal = oldVal.blend(this, m);
 904          newVal.intoArray(a, ax, b, iy);
 905      }
 906 
 907     @Override
 908     @ForceInline
 909     public void intoByteArray(byte[] a, int ix) {
 910         Objects.requireNonNull(a);
 911         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 912         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 913                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 914                                this,
 915                                a, ix,
 916                                (c, idx, v) -> {
 917                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 918                                    LongBuffer tb = bbc.asLongBuffer();
 919                                    v.forEach((i, e) -> tb.put(e));
 920                                });
 921     }
 922 
 923     @Override
 924     @ForceInline
 925     public final void intoByteArray(byte[] a, int ix, VectorMask<Long> m) {
 926         Long64Vector oldVal = (Long64Vector) LongVector.fromByteArray(SPECIES, a, ix);
 927         Long64Vector newVal = oldVal.blend(this, m);
 928         newVal.intoByteArray(a, ix);
 929     }
 930 
 931     @Override
 932     @ForceInline
 933     public void intoByteBuffer(ByteBuffer bb, int ix) {
 934         if (bb.order() != ByteOrder.nativeOrder()) {
 935             throw new IllegalArgumentException();
 936         }
 937         if (bb.isReadOnly()) {
 938             throw new ReadOnlyBufferException();
 939         }
 940         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 941         VectorIntrinsics.store(Long64Vector.class, long.class, LENGTH,
 942                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 943                                this,
 944                                bb, ix,
 945                                (c, idx, v) -> {
 946                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 947                                    LongBuffer tb = bbc.asLongBuffer();
 948                                    v.forEach((i, e) -> tb.put(e));
 949                                });
 950     }
 951 
 952     @Override
 953     @ForceInline
 954     public void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<Long> m) {
 955         Long64Vector oldVal = (Long64Vector) LongVector.fromByteBuffer(SPECIES, bb, ix);
 956         Long64Vector newVal = oldVal.blend(this, m);
 957         newVal.intoByteBuffer(bb, ix);
 958     }
 959 
 960     //
 961 
 962     @Override
 963     public String toString() {
 964         return Arrays.toString(getElements());
 965     }
 966 
 967     @Override
 968     public boolean equals(Object o) {
 969         if (this == o) return true;
 970         if (o == null || this.getClass() != o.getClass()) return false;
 971 
 972         Long64Vector that = (Long64Vector) o;
 973         return this.equal(that).allTrue();
 974     }
 975 
 976     @Override
 977     public int hashCode() {
 978         return Arrays.hashCode(vec);
 979     }
 980 
 981     // Binary test
 982 
 983     @Override
 984     Long64Mask bTest(Vector<Long> o, FBinTest f) {
 985         long[] vec1 = getElements();
 986         long[] vec2 = ((Long64Vector)o).getElements();
 987         boolean[] bits = new boolean[length()];
 988         for (int i = 0; i < length(); i++){
 989             bits[i] = f.apply(i, vec1[i], vec2[i]);
 990         }
 991         return new Long64Mask(bits);
 992     }
 993 
 994     // Comparisons
 995 
 996     @Override
 997     @ForceInline
 998     public Long64Mask equal(Vector<Long> o) {
 999         Objects.requireNonNull(o);
1000         Long64Vector v = (Long64Vector)o;
1001 
1002         return VectorIntrinsics.compare(
1003             BT_eq, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1004             this, v,
1005             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1006     }
1007 
1008     @Override
1009     @ForceInline
1010     public Long64Mask notEqual(Vector<Long> o) {
1011         Objects.requireNonNull(o);
1012         Long64Vector v = (Long64Vector)o;
1013 
1014         return VectorIntrinsics.compare(
1015             BT_ne, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1016             this, v,
1017             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1018     }
1019 
1020     @Override
1021     @ForceInline
1022     public Long64Mask lessThan(Vector<Long> o) {
1023         Objects.requireNonNull(o);
1024         Long64Vector v = (Long64Vector)o;
1025 
1026         return VectorIntrinsics.compare(
1027             BT_lt, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1028             this, v,
1029             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1030     }
1031 
1032     @Override
1033     @ForceInline
1034     public Long64Mask lessThanEq(Vector<Long> o) {
1035         Objects.requireNonNull(o);
1036         Long64Vector v = (Long64Vector)o;
1037 
1038         return VectorIntrinsics.compare(
1039             BT_le, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1040             this, v,
1041             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1042     }
1043 
1044     @Override
1045     @ForceInline
1046     public Long64Mask greaterThan(Vector<Long> o) {
1047         Objects.requireNonNull(o);
1048         Long64Vector v = (Long64Vector)o;
1049 
1050         return (Long64Mask) VectorIntrinsics.compare(
1051             BT_gt, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1052             this, v,
1053             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1054     }
1055 
1056     @Override
1057     @ForceInline
1058     public Long64Mask greaterThanEq(Vector<Long> o) {
1059         Objects.requireNonNull(o);
1060         Long64Vector v = (Long64Vector)o;
1061 
1062         return VectorIntrinsics.compare(
1063             BT_ge, Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1064             this, v,
1065             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1066     }
1067 
1068     // Foreach
1069 
1070     @Override
1071     void forEach(FUnCon f) {
1072         long[] vec = getElements();
1073         for (int i = 0; i < length(); i++) {
1074             f.apply(i, vec[i]);
1075         }
1076     }
1077 
1078     @Override
1079     void forEach(VectorMask<Long> o, FUnCon f) {
1080         boolean[] mbits = ((Long64Mask)o).getBits();
1081         forEach((i, a) -> {
1082             if (mbits[i]) { f.apply(i, a); }
1083         });
1084     }
1085 
1086 
1087     Double64Vector toFP() {
1088         long[] vec = getElements();
1089         double[] res = new double[this.species().length()];
1090         for(int i = 0; i < this.species().length(); i++){
1091             res[i] = Double.longBitsToDouble(vec[i]);
1092         }
1093         return new Double64Vector(res);
1094     }
1095 
1096     @Override
1097     public Long64Vector rotateEL(int j) {
1098         long[] vec = getElements();
1099         long[] res = new long[length()];
1100         for (int i = 0; i < length(); i++){
1101             res[(j + i) % length()] = vec[i];
1102         }
1103         return new Long64Vector(res);
1104     }
1105 
1106     @Override
1107     public Long64Vector rotateER(int j) {
1108         long[] vec = getElements();
1109         long[] res = new long[length()];
1110         for (int i = 0; i < length(); i++){
1111             int z = i - j;
1112             if(j < 0) {
1113                 res[length() + z] = vec[i];
1114             } else {
1115                 res[z] = vec[i];
1116             }
1117         }
1118         return new Long64Vector(res);
1119     }
1120 
1121     @Override
1122     public Long64Vector shiftEL(int j) {
1123         long[] vec = getElements();
1124         long[] res = new long[length()];
1125         for (int i = 0; i < length() - j; i++) {
1126             res[i] = vec[i + j];
1127         }
1128         return new Long64Vector(res);
1129     }
1130 
1131     @Override
1132     public Long64Vector shiftER(int j) {
1133         long[] vec = getElements();
1134         long[] res = new long[length()];
1135         for (int i = 0; i < length() - j; i++){
1136             res[i + j] = vec[i];
1137         }
1138         return new Long64Vector(res);
1139     }
1140 
1141     @Override
1142     @ForceInline
1143     public Long64Vector rearrange(Vector<Long> v,
1144                                   VectorShuffle<Long> s, VectorMask<Long> m) {
1145         return this.rearrange(s).blend(v.rearrange(s), m);
1146     }
1147 
1148     @Override
1149     @ForceInline
1150     public Long64Vector rearrange(VectorShuffle<Long> o1) {
1151         Objects.requireNonNull(o1);
1152         Long64Shuffle s =  (Long64Shuffle)o1;
1153 
1154         return VectorIntrinsics.rearrangeOp(
1155             Long64Vector.class, Long64Shuffle.class, long.class, LENGTH,
1156             this, s,
1157             (v1, s_) -> v1.uOp((i, a) -> {
1158                 int ei = s_.getElement(i);
1159                 return v1.get(ei);
1160             }));
1161     }
1162 
1163     @Override
1164     @ForceInline
1165     public Long64Vector blend(Vector<Long> o1, VectorMask<Long> o2) {
1166         Objects.requireNonNull(o1);
1167         Objects.requireNonNull(o2);
1168         Long64Vector v = (Long64Vector)o1;
1169         Long64Mask   m = (Long64Mask)o2;
1170 
1171         return VectorIntrinsics.blend(
1172             Long64Vector.class, Long64Mask.class, long.class, LENGTH,
1173             this, v, m,
1174             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1175     }
1176 
1177     // Accessors
1178 
1179     @Override
1180     public long get(int i) {
1181         if (i < 0 || i >= LENGTH) {
1182             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1183         }
1184         return (long) VectorIntrinsics.extract(
1185                                 Long64Vector.class, long.class, LENGTH,
1186                                 this, i,
1187                                 (vec, ix) -> {
1188                                     long[] vecarr = vec.getElements();
1189                                     return (long)vecarr[ix];
1190                                 });
1191     }
1192 
1193     @Override
1194     public Long64Vector with(int i, long e) {
1195         if (i < 0 || i >= LENGTH) {
1196             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1197         }
1198         return VectorIntrinsics.insert(
1199                                 Long64Vector.class, long.class, LENGTH,
1200                                 this, i, (long)e,
1201                                 (v, ix, bits) -> {
1202                                     long[] res = v.getElements().clone();
1203                                     res[ix] = (long)bits;
1204                                     return new Long64Vector(res);
1205                                 });
1206     }
1207 
1208     // Mask
1209 
1210     static final class Long64Mask extends AbstractMask<Long> {
1211         static final Long64Mask TRUE_MASK = new Long64Mask(true);
1212         static final Long64Mask FALSE_MASK = new Long64Mask(false);
1213 
1214         private final boolean[] bits; // Don't access directly, use getBits() instead.
1215 
1216         public Long64Mask(boolean[] bits) {
1217             this(bits, 0);
1218         }
1219 
1220         public Long64Mask(boolean[] bits, int offset) {
1221             boolean[] a = new boolean[species().length()];
1222             for (int i = 0; i < a.length; i++) {
1223                 a[i] = bits[offset + i];
1224             }
1225             this.bits = a;
1226         }
1227 
1228         public Long64Mask(boolean val) {
1229             boolean[] bits = new boolean[species().length()];
1230             Arrays.fill(bits, val);
1231             this.bits = bits;
1232         }
1233 
1234         boolean[] getBits() {
1235             return VectorIntrinsics.maybeRebox(this).bits;
1236         }
1237 
1238         @Override
1239         Long64Mask uOp(MUnOp f) {
1240             boolean[] res = new boolean[species().length()];
1241             boolean[] bits = getBits();
1242             for (int i = 0; i < species().length(); i++) {
1243                 res[i] = f.apply(i, bits[i]);
1244             }
1245             return new Long64Mask(res);
1246         }
1247 
1248         @Override
1249         Long64Mask bOp(VectorMask<Long> o, MBinOp f) {
1250             boolean[] res = new boolean[species().length()];
1251             boolean[] bits = getBits();
1252             boolean[] mbits = ((Long64Mask)o).getBits();
1253             for (int i = 0; i < species().length(); i++) {
1254                 res[i] = f.apply(i, bits[i], mbits[i]);
1255             }
1256             return new Long64Mask(res);
1257         }
1258 
1259         @Override
1260         public VectorSpecies<Long> species() {
1261             return SPECIES;
1262         }
1263 
1264         @Override
1265         public Long64Vector toVector() {
1266             long[] res = new long[species().length()];
1267             boolean[] bits = getBits();
1268             for (int i = 0; i < species().length(); i++) {
1269                 // -1 will result in the most significant bit being set in
1270                 // addition to some or all other bits
1271                 res[i] = (long) (bits[i] ? -1 : 0);
1272             }
1273             return new Long64Vector(res);
1274         }
1275 
1276         @Override
1277         @ForceInline
1278         @SuppressWarnings("unchecked")
1279         public <E> VectorMask<E> cast(VectorSpecies<E> species) {
1280             if (length() != species.length())
1281                 throw new IllegalArgumentException("VectorMask length and species length differ");
1282             Class<?> stype = species.elementType();
1283             boolean [] maskArray = toArray();
1284             if (stype == byte.class) {
1285                 return (VectorMask <E>) new Byte64Vector.Byte64Mask(maskArray);
1286             } else if (stype == short.class) {
1287                 return (VectorMask <E>) new Short64Vector.Short64Mask(maskArray);
1288             } else if (stype == int.class) {
1289                 return (VectorMask <E>) new Int64Vector.Int64Mask(maskArray);
1290             } else if (stype == long.class) {
1291                 return (VectorMask <E>) new Long64Vector.Long64Mask(maskArray);
1292             } else if (stype == float.class) {
1293                 return (VectorMask <E>) new Float64Vector.Float64Mask(maskArray);
1294             } else if (stype == double.class) {
1295                 return (VectorMask <E>) new Double64Vector.Double64Mask(maskArray);
1296             } else {
1297                 throw new UnsupportedOperationException("Bad lane type for casting.");
1298             }
1299         }
1300 
1301         // Unary operations
1302 
1303         @Override
1304         @ForceInline
1305         public Long64Mask not() {
1306             return (Long64Mask) VectorIntrinsics.unaryOp(
1307                                              VECTOR_OP_NOT, Long64Mask.class, long.class, LENGTH,
1308                                              this,
1309                                              (m1) -> m1.uOp((i, a) -> !a));
1310         }
1311 
1312         // Binary operations
1313 
1314         @Override
1315         @ForceInline
1316         public Long64Mask and(VectorMask<Long> o) {
1317             Objects.requireNonNull(o);
1318             Long64Mask m = (Long64Mask)o;
1319             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long64Mask.class, long.class, LENGTH,
1320                                              this, m,
1321                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1322         }
1323 
1324         @Override
1325         @ForceInline
1326         public Long64Mask or(VectorMask<Long> o) {
1327             Objects.requireNonNull(o);
1328             Long64Mask m = (Long64Mask)o;
1329             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Long64Mask.class, long.class, LENGTH,
1330                                              this, m,
1331                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1332         }
1333 
1334         // Reductions
1335 
1336         @Override
1337         @ForceInline
1338         public boolean anyTrue() {
1339             return VectorIntrinsics.test(BT_ne, Long64Mask.class, long.class, LENGTH,
1340                                          this, this,
1341                                          (m, __) -> anyTrueHelper(((Long64Mask)m).getBits()));
1342         }
1343 
1344         @Override
1345         @ForceInline
1346         public boolean allTrue() {
1347             return VectorIntrinsics.test(BT_overflow, Long64Mask.class, long.class, LENGTH,
1348                                          this, VectorMask.maskAllTrue(species()),
1349                                          (m, __) -> allTrueHelper(((Long64Mask)m).getBits()));
1350         }
1351     }
1352 
1353     // Shuffle
1354 
1355     static final class Long64Shuffle extends AbstractShuffle<Long> {
1356         Long64Shuffle(byte[] reorder) {
1357             super(reorder);
1358         }
1359 
1360         public Long64Shuffle(int[] reorder) {
1361             super(reorder);
1362         }
1363 
1364         public Long64Shuffle(int[] reorder, int i) {
1365             super(reorder, i);
1366         }
1367 
1368         public Long64Shuffle(IntUnaryOperator f) {
1369             super(f);
1370         }
1371 
1372         @Override
1373         public VectorSpecies<Long> species() {
1374             return SPECIES;
1375         }
1376 
1377         @Override
1378         public LongVector toVector() {
1379             long[] va = new long[SPECIES.length()];
1380             for (int i = 0; i < va.length; i++) {
1381               va[i] = (long) getElement(i);
1382             }
1383             return LongVector.fromArray(SPECIES, va, 0);
1384         }
1385 
1386         @Override
1387         @ForceInline
1388         @SuppressWarnings("unchecked")
1389         public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1390             if (length() != species.length())
1391                 throw new IllegalArgumentException("Shuffle length and species length differ");
1392             Class<?> stype = species.elementType();
1393             int [] shuffleArray = toArray();
1394             if (stype == byte.class) {
1395                 return (VectorShuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1396             } else if (stype == short.class) {
1397                 return (VectorShuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1398             } else if (stype == int.class) {
1399                 return (VectorShuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1400             } else if (stype == long.class) {
1401                 return (VectorShuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
1402             } else if (stype == float.class) {
1403                 return (VectorShuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
1404             } else if (stype == double.class) {
1405                 return (VectorShuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
1406             } else {
1407                 throw new UnsupportedOperationException("Bad lane type for casting.");
1408             }
1409         }
1410 
1411         @Override
1412         public Long64Shuffle rearrange(VectorShuffle<Long> o) {
1413             Long64Shuffle s = (Long64Shuffle) o;
1414             byte[] r = new byte[reorder.length];
1415             for (int i = 0; i < reorder.length; i++) {
1416                 r[i] = reorder[s.reorder[i]];
1417             }
1418             return new Long64Shuffle(r);
1419         }
1420     }
1421 
1422     // VectorSpecies
1423 
1424     @Override
1425     public VectorSpecies<Long> species() {
1426         return SPECIES;
1427     }
1428 }