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