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