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