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