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