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.ShortBuffer;
  30 import java.nio.ReadOnlyBufferException;
  31 import java.util.Arrays;
  32 import java.util.Objects;
  33 import java.util.function.IntUnaryOperator;
  34 
  35 import jdk.internal.misc.Unsafe;
  36 import jdk.internal.vm.annotation.ForceInline;
  37 import static jdk.incubator.vector.VectorIntrinsics.*;
  38 
  39 @SuppressWarnings("cast")
  40 final class Short64Vector extends ShortVector {
  41     private static final VectorSpecies<Short> SPECIES = ShortVector.SPECIES_64;
  42 
  43     static final Short64Vector ZERO = new Short64Vector();
  44 
  45     static final int LENGTH = SPECIES.length();
  46 
  47     private final short[] vec; // Don't access directly, use getElements() instead.
  48 
  49     private short[] getElements() {
  50         return VectorIntrinsics.maybeRebox(this).vec;
  51     }
  52 
  53     Short64Vector() {
  54         vec = new short[SPECIES.length()];
  55     }
  56 
  57     Short64Vector(short[] v) {
  58         vec = v;
  59     }
  60 
  61     @Override
  62     public int length() { return LENGTH; }
  63 
  64     // Unary operator
  65 
  66     @Override
  67     Short64Vector uOp(FUnOp f) {
  68         short[] vec = getElements();
  69         short[] res = new short[length()];
  70         for (int i = 0; i < length(); i++) {
  71             res[i] = f.apply(i, vec[i]);
  72         }
  73         return new Short64Vector(res);
  74     }
  75 
  76     @Override
  77     Short64Vector uOp(VectorMask<Short> o, FUnOp f) {
  78         short[] vec = getElements();
  79         short[] res = new short[length()];
  80         boolean[] mbits = ((Short64Mask)o).getBits();
  81         for (int i = 0; i < length(); i++) {
  82             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
  83         }
  84         return new Short64Vector(res);
  85     }
  86 
  87     // Binary operator
  88 
  89     @Override
  90     Short64Vector bOp(Vector<Short> o, FBinOp f) {
  91         short[] res = new short[length()];
  92         short[] vec1 = this.getElements();
  93         short[] vec2 = ((Short64Vector)o).getElements();
  94         for (int i = 0; i < length(); i++) {
  95             res[i] = f.apply(i, vec1[i], vec2[i]);
  96         }
  97         return new Short64Vector(res);
  98     }
  99 
 100     @Override
 101     Short64Vector bOp(Vector<Short> o1, VectorMask<Short> o2, FBinOp f) {
 102         short[] res = new short[length()];
 103         short[] vec1 = this.getElements();
 104         short[] vec2 = ((Short64Vector)o1).getElements();
 105         boolean[] mbits = ((Short64Mask)o2).getBits();
 106         for (int i = 0; i < length(); i++) {
 107             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
 108         }
 109         return new Short64Vector(res);
 110     }
 111 
 112     // Trinary operator
 113 
 114     @Override
 115     Short64Vector tOp(Vector<Short> o1, Vector<Short> o2, FTriOp f) {
 116         short[] res = new short[length()];
 117         short[] vec1 = this.getElements();
 118         short[] vec2 = ((Short64Vector)o1).getElements();
 119         short[] vec3 = ((Short64Vector)o2).getElements();
 120         for (int i = 0; i < length(); i++) {
 121             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
 122         }
 123         return new Short64Vector(res);
 124     }
 125 
 126     @Override
 127     Short64Vector tOp(Vector<Short> o1, Vector<Short> o2, VectorMask<Short> o3, FTriOp f) {
 128         short[] res = new short[length()];
 129         short[] vec1 = getElements();
 130         short[] vec2 = ((Short64Vector)o1).getElements();
 131         short[] vec3 = ((Short64Vector)o2).getElements();
 132         boolean[] mbits = ((Short64Mask)o3).getBits();
 133         for (int i = 0; i < length(); i++) {
 134             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
 135         }
 136         return new Short64Vector(res);
 137     }
 138 
 139     @Override
 140     short rOp(short v, FBinOp f) {
 141         short[] vec = getElements();
 142         for (int i = 0; i < length(); i++) {
 143             v = f.apply(i, v, vec[i]);
 144         }
 145         return v;
 146     }
 147 
 148     @Override
 149     @ForceInline
 150     public <F> Vector<F> cast(VectorSpecies<F> s) {
 151         Objects.requireNonNull(s);
 152         if (s.length() != LENGTH)
 153             throw new IllegalArgumentException("Vector length this species length differ");
 154 
 155         return VectorIntrinsics.cast(
 156             Short64Vector.class,
 157             short.class, LENGTH,
 158             s.vectorType(),
 159             s.elementType(), LENGTH,
 160             this, s,
 161             (species, vector) -> vector.castDefault(species)
 162         );
 163     }
 164 
 165     @SuppressWarnings("unchecked")
 166     @ForceInline
 167     private <F> Vector<F> castDefault(VectorSpecies<F> s) {
 168         int limit = s.length();
 169 
 170         Class<?> stype = s.elementType();
 171         if (stype == byte.class) {
 172             byte[] a = new byte[limit];
 173             for (int i = 0; i < limit; i++) {
 174                 a[i] = (byte) this.lane(i);
 175             }
 176             return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
 177         } else if (stype == short.class) {
 178             short[] a = new short[limit];
 179             for (int i = 0; i < limit; i++) {
 180                 a[i] = (short) this.lane(i);
 181             }
 182             return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
 183         } else if (stype == int.class) {
 184             int[] a = new int[limit];
 185             for (int i = 0; i < limit; i++) {
 186                 a[i] = (int) this.lane(i);
 187             }
 188             return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
 189         } else if (stype == long.class) {
 190             long[] a = new long[limit];
 191             for (int i = 0; i < limit; i++) {
 192                 a[i] = (long) this.lane(i);
 193             }
 194             return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
 195         } else if (stype == float.class) {
 196             float[] a = new float[limit];
 197             for (int i = 0; i < limit; i++) {
 198                 a[i] = (float) this.lane(i);
 199             }
 200             return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
 201         } else if (stype == double.class) {
 202             double[] a = new double[limit];
 203             for (int i = 0; i < limit; i++) {
 204                 a[i] = (double) this.lane(i);
 205             }
 206             return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
 207         } else {
 208             throw new UnsupportedOperationException("Bad lane type for casting.");
 209         }
 210     }
 211 
 212     @Override
 213     @ForceInline
 214     @SuppressWarnings("unchecked")
 215     public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
 216         Objects.requireNonNull(s);
 217 
 218         if(s.elementType().equals(short.class)) {
 219             return (Vector<F>) reshape((VectorSpecies<Short>)s);
 220         }
 221         if(s.bitSize() == bitSize()) {
 222             return reinterpretType(s);
 223         }
 224 
 225         return defaultReinterpret(s);
 226     }
 227 
 228     @ForceInline
 229     private <F> Vector<F> reinterpretType(VectorSpecies<F> s) {
 230         Objects.requireNonNull(s);
 231 
 232         Class<?> stype = s.elementType();
 233         if (stype == byte.class) {
 234             return VectorIntrinsics.reinterpret(
 235                 Short64Vector.class,
 236                 short.class, LENGTH,
 237                 Byte64Vector.class,
 238                 byte.class, Byte64Vector.LENGTH,
 239                 this, s,
 240                 (species, vector) -> vector.defaultReinterpret(species)
 241             );
 242         } else if (stype == short.class) {
 243             return VectorIntrinsics.reinterpret(
 244                 Short64Vector.class,
 245                 short.class, LENGTH,
 246                 Short64Vector.class,
 247                 short.class, Short64Vector.LENGTH,
 248                 this, s,
 249                 (species, vector) -> vector.defaultReinterpret(species)
 250             );
 251         } else if (stype == int.class) {
 252             return VectorIntrinsics.reinterpret(
 253                 Short64Vector.class,
 254                 short.class, LENGTH,
 255                 Int64Vector.class,
 256                 int.class, Int64Vector.LENGTH,
 257                 this, s,
 258                 (species, vector) -> vector.defaultReinterpret(species)
 259             );
 260         } else if (stype == long.class) {
 261             return VectorIntrinsics.reinterpret(
 262                 Short64Vector.class,
 263                 short.class, LENGTH,
 264                 Long64Vector.class,
 265                 long.class, Long64Vector.LENGTH,
 266                 this, s,
 267                 (species, vector) -> vector.defaultReinterpret(species)
 268             );
 269         } else if (stype == float.class) {
 270             return VectorIntrinsics.reinterpret(
 271                 Short64Vector.class,
 272                 short.class, LENGTH,
 273                 Float64Vector.class,
 274                 float.class, Float64Vector.LENGTH,
 275                 this, s,
 276                 (species, vector) -> vector.defaultReinterpret(species)
 277             );
 278         } else if (stype == double.class) {
 279             return VectorIntrinsics.reinterpret(
 280                 Short64Vector.class,
 281                 short.class, LENGTH,
 282                 Double64Vector.class,
 283                 double.class, Double64Vector.LENGTH,
 284                 this, s,
 285                 (species, vector) -> vector.defaultReinterpret(species)
 286             );
 287         } else {
 288             throw new UnsupportedOperationException("Bad lane type for casting.");
 289         }
 290     }
 291 
 292     @Override
 293     @ForceInline
 294     public ShortVector reshape(VectorSpecies<Short> s) {
 295         Objects.requireNonNull(s);
 296         if (s.bitSize() == 64 && (s.vectorType() == Short64Vector.class)) {
 297             return VectorIntrinsics.reinterpret(
 298                 Short64Vector.class,
 299                 short.class, LENGTH,
 300                 Short64Vector.class,
 301                 short.class, Short64Vector.LENGTH,
 302                 this, s,
 303                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 304             );
 305         } else if (s.bitSize() == 128 && (s.vectorType() == Short128Vector.class)) {
 306             return VectorIntrinsics.reinterpret(
 307                 Short64Vector.class,
 308                 short.class, LENGTH,
 309                 Short128Vector.class,
 310                 short.class, Short128Vector.LENGTH,
 311                 this, s,
 312                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 313             );
 314         } else if (s.bitSize() == 256 && (s.vectorType() == Short256Vector.class)) {
 315             return VectorIntrinsics.reinterpret(
 316                 Short64Vector.class,
 317                 short.class, LENGTH,
 318                 Short256Vector.class,
 319                 short.class, Short256Vector.LENGTH,
 320                 this, s,
 321                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 322             );
 323         } else if (s.bitSize() == 512 && (s.vectorType() == Short512Vector.class)) {
 324             return VectorIntrinsics.reinterpret(
 325                 Short64Vector.class,
 326                 short.class, LENGTH,
 327                 Short512Vector.class,
 328                 short.class, Short512Vector.LENGTH,
 329                 this, s,
 330                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 331             );
 332         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 333                 && (s.bitSize() % 128 == 0) && (s.vectorType() == ShortMaxVector.class)) {
 334             return VectorIntrinsics.reinterpret(
 335                 Short64Vector.class,
 336                 short.class, LENGTH,
 337                 ShortMaxVector.class,
 338                 short.class, ShortMaxVector.LENGTH,
 339                 this, s,
 340                 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
 341             );
 342         } else {
 343             throw new InternalError("Unimplemented size");
 344         }
 345     }
 346 
 347     // Binary operations with scalars
 348 
 349     @Override
 350     @ForceInline
 351     public ShortVector add(short o) {
 352         return add((Short64Vector)ShortVector.broadcast(SPECIES, o));
 353     }
 354 
 355     @Override
 356     @ForceInline
 357     public ShortVector add(short o, VectorMask<Short> m) {
 358         return add((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 359     }
 360 
 361     @Override
 362     @ForceInline
 363     public ShortVector sub(short o) {
 364         return sub((Short64Vector)ShortVector.broadcast(SPECIES, o));
 365     }
 366 
 367     @Override
 368     @ForceInline
 369     public ShortVector sub(short o, VectorMask<Short> m) {
 370         return sub((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 371     }
 372 
 373     @Override
 374     @ForceInline
 375     public ShortVector mul(short o) {
 376         return mul((Short64Vector)ShortVector.broadcast(SPECIES, o));
 377     }
 378 
 379     @Override
 380     @ForceInline
 381     public ShortVector mul(short o, VectorMask<Short> m) {
 382         return mul((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 383     }
 384 
 385     @Override
 386     @ForceInline
 387     public ShortVector min(short o) {
 388         return min((Short64Vector)ShortVector.broadcast(SPECIES, o));
 389     }
 390 
 391     @Override
 392     @ForceInline
 393     public ShortVector max(short o) {
 394         return max((Short64Vector)ShortVector.broadcast(SPECIES, o));
 395     }
 396 
 397     @Override
 398     @ForceInline
 399     public VectorMask<Short> equal(short o) {
 400         return equal((Short64Vector)ShortVector.broadcast(SPECIES, o));
 401     }
 402 
 403     @Override
 404     @ForceInline
 405     public VectorMask<Short> notEqual(short o) {
 406         return notEqual((Short64Vector)ShortVector.broadcast(SPECIES, o));
 407     }
 408 
 409     @Override
 410     @ForceInline
 411     public VectorMask<Short> lessThan(short o) {
 412         return lessThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
 413     }
 414 
 415     @Override
 416     @ForceInline
 417     public VectorMask<Short> lessThanEq(short o) {
 418         return lessThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
 419     }
 420 
 421     @Override
 422     @ForceInline
 423     public VectorMask<Short> greaterThan(short o) {
 424         return greaterThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
 425     }
 426 
 427     @Override
 428     @ForceInline
 429     public VectorMask<Short> greaterThanEq(short o) {
 430         return greaterThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
 431     }
 432 
 433     @Override
 434     @ForceInline
 435     public ShortVector blend(short o, VectorMask<Short> m) {
 436         return blend((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 437     }
 438 
 439 
 440     @Override
 441     @ForceInline
 442     public ShortVector and(short o) {
 443         return and((Short64Vector)ShortVector.broadcast(SPECIES, o));
 444     }
 445 
 446     @Override
 447     @ForceInline
 448     public ShortVector and(short o, VectorMask<Short> m) {
 449         return and((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 450     }
 451 
 452     @Override
 453     @ForceInline
 454     public ShortVector or(short o) {
 455         return or((Short64Vector)ShortVector.broadcast(SPECIES, o));
 456     }
 457 
 458     @Override
 459     @ForceInline
 460     public ShortVector or(short o, VectorMask<Short> m) {
 461         return or((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 462     }
 463 
 464     @Override
 465     @ForceInline
 466     public ShortVector xor(short o) {
 467         return xor((Short64Vector)ShortVector.broadcast(SPECIES, o));
 468     }
 469 
 470     @Override
 471     @ForceInline
 472     public ShortVector xor(short o, VectorMask<Short> m) {
 473         return xor((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
 474     }
 475 
 476     @Override
 477     @ForceInline
 478     public Short64Vector neg() {
 479         return (Short64Vector)zero(SPECIES).sub(this);
 480     }
 481 
 482     // Unary operations
 483 
 484     @ForceInline
 485     @Override
 486     public Short64Vector neg(VectorMask<Short> m) {
 487         return blend(neg(), m);
 488     }
 489 
 490     @Override
 491     @ForceInline
 492     public Short64Vector abs() {
 493         return VectorIntrinsics.unaryOp(
 494             VECTOR_OP_ABS, Short64Vector.class, short.class, LENGTH,
 495             this,
 496             v1 -> v1.uOp((i, a) -> (short) Math.abs(a)));
 497     }
 498 
 499     @ForceInline
 500     @Override
 501     public Short64Vector abs(VectorMask<Short> m) {
 502         return blend(abs(), m);
 503     }
 504 
 505 
 506     @Override
 507     @ForceInline
 508     public Short64Vector not() {
 509         return VectorIntrinsics.unaryOp(
 510             VECTOR_OP_NOT, Short64Vector.class, short.class, LENGTH,
 511             this,
 512             v1 -> v1.uOp((i, a) -> (short) ~a));
 513     }
 514 
 515     @ForceInline
 516     @Override
 517     public Short64Vector not(VectorMask<Short> m) {
 518         return blend(not(), m);
 519     }
 520     // Binary operations
 521 
 522     @Override
 523     @ForceInline
 524     public Short64Vector add(Vector<Short> o) {
 525         Objects.requireNonNull(o);
 526         Short64Vector v = (Short64Vector)o;
 527         return VectorIntrinsics.binaryOp(
 528             VECTOR_OP_ADD, Short64Vector.class, short.class, LENGTH,
 529             this, v,
 530             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a + b)));
 531     }
 532 
 533     @Override
 534     @ForceInline
 535     public Short64Vector add(Vector<Short> v, VectorMask<Short> m) {
 536         return blend(add(v), m);
 537     }
 538 
 539     @Override
 540     @ForceInline
 541     public Short64Vector sub(Vector<Short> o) {
 542         Objects.requireNonNull(o);
 543         Short64Vector v = (Short64Vector)o;
 544         return VectorIntrinsics.binaryOp(
 545             VECTOR_OP_SUB, Short64Vector.class, short.class, LENGTH,
 546             this, v,
 547             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a - b)));
 548     }
 549 
 550     @Override
 551     @ForceInline
 552     public Short64Vector sub(Vector<Short> v, VectorMask<Short> m) {
 553         return blend(sub(v), m);
 554     }
 555 
 556     @Override
 557     @ForceInline
 558     public Short64Vector mul(Vector<Short> o) {
 559         Objects.requireNonNull(o);
 560         Short64Vector v = (Short64Vector)o;
 561         return VectorIntrinsics.binaryOp(
 562             VECTOR_OP_MUL, Short64Vector.class, short.class, LENGTH,
 563             this, v,
 564             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a * b)));
 565     }
 566 
 567     @Override
 568     @ForceInline
 569     public Short64Vector mul(Vector<Short> v, VectorMask<Short> m) {
 570         return blend(mul(v), m);
 571     }
 572 
 573     @Override
 574     @ForceInline
 575     public Short64Vector min(Vector<Short> o) {
 576         Objects.requireNonNull(o);
 577         Short64Vector v = (Short64Vector)o;
 578         return (Short64Vector) VectorIntrinsics.binaryOp(
 579             VECTOR_OP_MIN, Short64Vector.class, short.class, LENGTH,
 580             this, v,
 581             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.min(a, b)));
 582     }
 583 
 584     @Override
 585     @ForceInline
 586     public Short64Vector min(Vector<Short> v, VectorMask<Short> m) {
 587         return blend(min(v), m);
 588     }
 589 
 590     @Override
 591     @ForceInline
 592     public Short64Vector max(Vector<Short> o) {
 593         Objects.requireNonNull(o);
 594         Short64Vector v = (Short64Vector)o;
 595         return VectorIntrinsics.binaryOp(
 596             VECTOR_OP_MAX, Short64Vector.class, short.class, LENGTH,
 597             this, v,
 598             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.max(a, b)));
 599         }
 600 
 601     @Override
 602     @ForceInline
 603     public Short64Vector max(Vector<Short> v, VectorMask<Short> m) {
 604         return blend(max(v), m);
 605     }
 606 
 607     @Override
 608     @ForceInline
 609     public Short64Vector and(Vector<Short> o) {
 610         Objects.requireNonNull(o);
 611         Short64Vector v = (Short64Vector)o;
 612         return VectorIntrinsics.binaryOp(
 613             VECTOR_OP_AND, Short64Vector.class, short.class, LENGTH,
 614             this, v,
 615             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a & b)));
 616     }
 617 
 618     @Override
 619     @ForceInline
 620     public Short64Vector or(Vector<Short> o) {
 621         Objects.requireNonNull(o);
 622         Short64Vector v = (Short64Vector)o;
 623         return VectorIntrinsics.binaryOp(
 624             VECTOR_OP_OR, Short64Vector.class, short.class, LENGTH,
 625             this, v,
 626             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a | b)));
 627     }
 628 
 629     @Override
 630     @ForceInline
 631     public Short64Vector xor(Vector<Short> o) {
 632         Objects.requireNonNull(o);
 633         Short64Vector v = (Short64Vector)o;
 634         return VectorIntrinsics.binaryOp(
 635             VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
 636             this, v,
 637             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a ^ b)));
 638     }
 639 
 640     @Override
 641     @ForceInline
 642     public Short64Vector and(Vector<Short> v, VectorMask<Short> m) {
 643         return blend(and(v), m);
 644     }
 645 
 646     @Override
 647     @ForceInline
 648     public Short64Vector or(Vector<Short> v, VectorMask<Short> m) {
 649         return blend(or(v), m);
 650     }
 651 
 652     @Override
 653     @ForceInline
 654     public Short64Vector xor(Vector<Short> v, VectorMask<Short> m) {
 655         return blend(xor(v), m);
 656     }
 657 
 658     @Override
 659     @ForceInline
 660     public Short64Vector shiftLeft(int s) {
 661         return VectorIntrinsics.broadcastInt(
 662             VECTOR_OP_LSHIFT, Short64Vector.class, short.class, LENGTH,
 663             this, s,
 664             (v, i) -> v.uOp((__, a) -> (short) (a << (i & 0xF))));
 665     }
 666 
 667     @Override
 668     @ForceInline
 669     public Short64Vector shiftLeft(int s, VectorMask<Short> m) {
 670         return blend(shiftLeft(s), m);
 671     }
 672 
 673     @Override
 674     @ForceInline
 675     public Short64Vector shiftLeft(Vector<Short> s) {
 676         Short64Vector shiftv = (Short64Vector)s;
 677         // As per shift specification for Java, mask the shift count.
 678         shiftv = shiftv.and(ShortVector.broadcast(SPECIES, (short) 0xF));
 679         return this.bOp(shiftv, (i, a, b) -> (short) (a << (b & 0xF)));
 680     }
 681 
 682     @Override
 683     @ForceInline
 684     public Short64Vector shiftRight(int s) {
 685         return VectorIntrinsics.broadcastInt(
 686             VECTOR_OP_URSHIFT, Short64Vector.class, short.class, LENGTH,
 687             this, s,
 688             (v, i) -> v.uOp((__, a) -> (short) ((a & 0xFFFF) >>> (i & 0xF))));
 689     }
 690 
 691     @Override
 692     @ForceInline
 693     public Short64Vector shiftRight(int s, VectorMask<Short> m) {
 694         return blend(shiftRight(s), m);
 695     }
 696 
 697     @Override
 698     @ForceInline
 699     public Short64Vector shiftRight(Vector<Short> s) {
 700         Short64Vector shiftv = (Short64Vector)s;
 701         // As per shift specification for Java, mask the shift count.
 702         shiftv = shiftv.and(ShortVector.broadcast(SPECIES, (short) 0xF));
 703         return this.bOp(shiftv, (i, a, b) -> (short) (a >>> (b & 0xF)));
 704     }
 705 
 706     @Override
 707     @ForceInline
 708     public Short64Vector shiftArithmeticRight(int s) {
 709         return VectorIntrinsics.broadcastInt(
 710             VECTOR_OP_RSHIFT, Short64Vector.class, short.class, LENGTH,
 711             this, s,
 712             (v, i) -> v.uOp((__, a) -> (short) (a >> (i & 0xF))));
 713     }
 714 
 715     @Override
 716     @ForceInline
 717     public Short64Vector shiftArithmeticRight(int s, VectorMask<Short> m) {
 718         return blend(shiftArithmeticRight(s), m);
 719     }
 720 
 721     @Override
 722     @ForceInline
 723     public Short64Vector shiftArithmeticRight(Vector<Short> s) {
 724         Short64Vector shiftv = (Short64Vector)s;
 725         // As per shift specification for Java, mask the shift count.
 726         shiftv = shiftv.and(ShortVector.broadcast(SPECIES, (short) 0xF));
 727         return this.bOp(shiftv, (i, a, b) -> (short) (a >> (b & 0xF)));
 728     }
 729     // Ternary operations
 730 
 731 
 732     // Type specific horizontal reductions
 733 
 734     @Override
 735     @ForceInline
 736     public short addLanes() {
 737         return (short) VectorIntrinsics.reductionCoerced(
 738             VECTOR_OP_ADD, Short64Vector.class, short.class, LENGTH,
 739             this,
 740             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a + b)));
 741     }
 742 
 743     @Override
 744     @ForceInline
 745     public short andLanes() {
 746         return (short) VectorIntrinsics.reductionCoerced(
 747             VECTOR_OP_AND, Short64Vector.class, short.class, LENGTH,
 748             this,
 749             v -> (long) v.rOp((short) -1, (i, a, b) -> (short) (a & b)));
 750     }
 751 
 752     @Override
 753     @ForceInline
 754     public short andLanes(VectorMask<Short> m) {
 755         return ShortVector.broadcast(SPECIES, (short) -1).blend(this, m).andLanes();
 756     }
 757 
 758     @Override
 759     @ForceInline
 760     public short minLanes() {
 761         return (short) VectorIntrinsics.reductionCoerced(
 762             VECTOR_OP_MIN, Short64Vector.class, short.class, LENGTH,
 763             this,
 764             v -> (long) v.rOp(Short.MAX_VALUE , (i, a, b) -> (short) Math.min(a, b)));
 765     }
 766 
 767     @Override
 768     @ForceInline
 769     public short maxLanes() {
 770         return (short) VectorIntrinsics.reductionCoerced(
 771             VECTOR_OP_MAX, Short64Vector.class, short.class, LENGTH,
 772             this,
 773             v -> (long) v.rOp(Short.MIN_VALUE , (i, a, b) -> (short) Math.max(a, b)));
 774     }
 775 
 776     @Override
 777     @ForceInline
 778     public short mulLanes() {
 779         return (short) VectorIntrinsics.reductionCoerced(
 780             VECTOR_OP_MUL, Short64Vector.class, short.class, LENGTH,
 781             this,
 782             v -> (long) v.rOp((short) 1, (i, a, b) -> (short) (a * b)));
 783     }
 784 
 785     @Override
 786     @ForceInline
 787     public short orLanes() {
 788         return (short) VectorIntrinsics.reductionCoerced(
 789             VECTOR_OP_OR, Short64Vector.class, short.class, LENGTH,
 790             this,
 791             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a | b)));
 792     }
 793 
 794     @Override
 795     @ForceInline
 796     public short orLanes(VectorMask<Short> m) {
 797         return ShortVector.broadcast(SPECIES, (short) 0).blend(this, m).orLanes();
 798     }
 799 
 800     @Override
 801     @ForceInline
 802     public short xorLanes() {
 803         return (short) VectorIntrinsics.reductionCoerced(
 804             VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
 805             this,
 806             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a ^ b)));
 807     }
 808 
 809     @Override
 810     @ForceInline
 811     public short xorLanes(VectorMask<Short> m) {
 812         return ShortVector.broadcast(SPECIES, (short) 0).blend(this, m).xorLanes();
 813     }
 814 
 815 
 816     @Override
 817     @ForceInline
 818     public short addLanes(VectorMask<Short> m) {
 819         return ShortVector.broadcast(SPECIES, (short) 0).blend(this, m).addLanes();
 820     }
 821 
 822 
 823     @Override
 824     @ForceInline
 825     public short mulLanes(VectorMask<Short> m) {
 826         return ShortVector.broadcast(SPECIES, (short) 1).blend(this, m).mulLanes();
 827     }
 828 
 829     @Override
 830     @ForceInline
 831     public short minLanes(VectorMask<Short> m) {
 832         return ShortVector.broadcast(SPECIES, Short.MAX_VALUE).blend(this, m).minLanes();
 833     }
 834 
 835     @Override
 836     @ForceInline
 837     public short maxLanes(VectorMask<Short> m) {
 838         return ShortVector.broadcast(SPECIES, Short.MIN_VALUE).blend(this, m).maxLanes();
 839     }
 840 
 841     @Override
 842     @ForceInline
 843     public VectorShuffle<Short> toShuffle() {
 844         short[] 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_SHORT_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(short[] a, int ix) {
 860         Objects.requireNonNull(a);
 861         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 862         VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
 863                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_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(short[] a, int ax, VectorMask<Short> m) {
 872         ShortVector oldVal = ShortVector.fromArray(SPECIES, a, ax);
 873         ShortVector 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(Short64Vector.class, short.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                                    ShortBuffer tb = bbc.asShortBuffer();
 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<Short> m) {
 896         Short64Vector oldVal = (Short64Vector) ShortVector.fromByteArray(SPECIES, a, ix);
 897         Short64Vector 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(Short64Vector.class, short.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                                    ShortBuffer tb = bbc.asShortBuffer();
 918                                    v.forEach((i, e) -> tb.put(e));
 919                                });
 920     }
 921 
 922     @Override
 923     @ForceInline
 924     public void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<Short> m) {
 925         Short64Vector oldVal = (Short64Vector) ShortVector.fromByteBuffer(SPECIES, bb, ix);
 926         Short64Vector 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         Short64Vector that = (Short64Vector) 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     Short64Mask bTest(Vector<Short> o, FBinTest f) {
 955         short[] vec1 = getElements();
 956         short[] vec2 = ((Short64Vector)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 Short64Mask(bits);
 962     }
 963 
 964     // Comparisons
 965 
 966     @Override
 967     @ForceInline
 968     public Short64Mask equal(Vector<Short> o) {
 969         Objects.requireNonNull(o);
 970         Short64Vector v = (Short64Vector)o;
 971 
 972         return VectorIntrinsics.compare(
 973             BT_eq, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 974             this, v,
 975             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
 976     }
 977 
 978     @Override
 979     @ForceInline
 980     public Short64Mask notEqual(Vector<Short> o) {
 981         Objects.requireNonNull(o);
 982         Short64Vector v = (Short64Vector)o;
 983 
 984         return VectorIntrinsics.compare(
 985             BT_ne, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 986             this, v,
 987             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
 988     }
 989 
 990     @Override
 991     @ForceInline
 992     public Short64Mask lessThan(Vector<Short> o) {
 993         Objects.requireNonNull(o);
 994         Short64Vector v = (Short64Vector)o;
 995 
 996         return VectorIntrinsics.compare(
 997             BT_lt, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 998             this, v,
 999             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1000     }
1001 
1002     @Override
1003     @ForceInline
1004     public Short64Mask lessThanEq(Vector<Short> o) {
1005         Objects.requireNonNull(o);
1006         Short64Vector v = (Short64Vector)o;
1007 
1008         return VectorIntrinsics.compare(
1009             BT_le, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1010             this, v,
1011             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1012     }
1013 
1014     @Override
1015     @ForceInline
1016     public Short64Mask greaterThan(Vector<Short> o) {
1017         Objects.requireNonNull(o);
1018         Short64Vector v = (Short64Vector)o;
1019 
1020         return (Short64Mask) VectorIntrinsics.compare(
1021             BT_gt, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1022             this, v,
1023             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1024     }
1025 
1026     @Override
1027     @ForceInline
1028     public Short64Mask greaterThanEq(Vector<Short> o) {
1029         Objects.requireNonNull(o);
1030         Short64Vector v = (Short64Vector)o;
1031 
1032         return VectorIntrinsics.compare(
1033             BT_ge, Short64Vector.class, Short64Mask.class, short.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         short[] 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<Short> o, FUnCon f) {
1050         boolean[] mbits = ((Short64Mask)o).getBits();
1051         forEach((i, a) -> {
1052             if (mbits[i]) { f.apply(i, a); }
1053         });
1054     }
1055 
1056 
1057 
1058     @Override
1059     public Short64Vector rotateLanesLeft(int j) {
1060         short[] vec = getElements();
1061         short[] res = new short[length()];
1062         for (int i = 0; i < length(); i++){
1063             res[(j + i) % length()] = vec[i];
1064         }
1065         return new Short64Vector(res);
1066     }
1067 
1068     @Override
1069     public Short64Vector rotateLanesRight(int j) {
1070         short[] vec = getElements();
1071         short[] res = new short[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 Short64Vector(res);
1081     }
1082 
1083     @Override
1084     public Short64Vector shiftLanesLeft(int j) {
1085         short[] vec = getElements();
1086         short[] res = new short[length()];
1087         for (int i = 0; i < length() - j; i++) {
1088             res[i] = vec[i + j];
1089         }
1090         return new Short64Vector(res);
1091     }
1092 
1093     @Override
1094     public Short64Vector shiftLanesRight(int j) {
1095         short[] vec = getElements();
1096         short[] res = new short[length()];
1097         for (int i = 0; i < length() - j; i++){
1098             res[i + j] = vec[i];
1099         }
1100         return new Short64Vector(res);
1101     }
1102 
1103     @Override
1104     @ForceInline
1105     public Short64Vector rearrange(Vector<Short> v,
1106                                   VectorShuffle<Short> s, VectorMask<Short> m) {
1107         return this.rearrange(s).blend(v.rearrange(s), m);
1108     }
1109 
1110     @Override
1111     @ForceInline
1112     public Short64Vector rearrange(VectorShuffle<Short> o1) {
1113         Objects.requireNonNull(o1);
1114         Short64Shuffle s =  (Short64Shuffle)o1;
1115 
1116         return VectorIntrinsics.rearrangeOp(
1117             Short64Vector.class, Short64Shuffle.class, short.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 Short64Vector blend(Vector<Short> o1, VectorMask<Short> o2) {
1128         Objects.requireNonNull(o1);
1129         Objects.requireNonNull(o2);
1130         Short64Vector v = (Short64Vector)o1;
1131         Short64Mask   m = (Short64Mask)o2;
1132 
1133         return VectorIntrinsics.blend(
1134             Short64Vector.class, Short64Mask.class, short.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 short 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 (short) VectorIntrinsics.extract(
1147                                 Short64Vector.class, short.class, LENGTH,
1148                                 this, i,
1149                                 (vec, ix) -> {
1150                                     short[] vecarr = vec.getElements();
1151                                     return (long)vecarr[ix];
1152                                 });
1153     }
1154 
1155     @Override
1156     public Short64Vector with(int i, short 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                                 Short64Vector.class, short.class, LENGTH,
1162                                 this, i, (long)e,
1163                                 (v, ix, bits) -> {
1164                                     short[] res = v.getElements().clone();
1165                                     res[ix] = (short)bits;
1166                                     return new Short64Vector(res);
1167                                 });
1168     }
1169 
1170     // Mask
1171 
1172     static final class Short64Mask extends AbstractMask<Short> {
1173         static final Short64Mask TRUE_MASK = new Short64Mask(true);
1174         static final Short64Mask FALSE_MASK = new Short64Mask(false);
1175 
1176         private final boolean[] bits; // Don't access directly, use getBits() instead.
1177 
1178         public Short64Mask(boolean[] bits) {
1179             this(bits, 0);
1180         }
1181 
1182         public Short64Mask(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 Short64Mask(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         Short64Mask 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 Short64Mask(res);
1208         }
1209 
1210         @Override
1211         Short64Mask bOp(VectorMask<Short> o, MBinOp f) {
1212             boolean[] res = new boolean[species().length()];
1213             boolean[] bits = getBits();
1214             boolean[] mbits = ((Short64Mask)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 Short64Mask(res);
1219         }
1220 
1221         @Override
1222         public VectorSpecies<Short> species() {
1223             return SPECIES;
1224         }
1225 
1226         @Override
1227         public Short64Vector toVector() {
1228             short[] res = new short[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] = (short) (bits[i] ? -1 : 0);
1234             }
1235             return new Short64Vector(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 Byte64Vector.Byte64Mask(maskArray);
1248             } else if (stype == short.class) {
1249                 return (VectorMask <E>) new Short64Vector.Short64Mask(maskArray);
1250             } else if (stype == int.class) {
1251                 return (VectorMask <E>) new Int64Vector.Int64Mask(maskArray);
1252             } else if (stype == long.class) {
1253                 return (VectorMask <E>) new Long64Vector.Long64Mask(maskArray);
1254             } else if (stype == float.class) {
1255                 return (VectorMask <E>) new Float64Vector.Float64Mask(maskArray);
1256             } else if (stype == double.class) {
1257                 return (VectorMask <E>) new Double64Vector.Double64Mask(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 Short64Mask not() {
1268             return (Short64Mask) VectorIntrinsics.unaryOp(
1269                                              VECTOR_OP_NOT, Short64Mask.class, short.class, LENGTH,
1270                                              this,
1271                                              (m1) -> m1.uOp((i, a) -> !a));
1272         }
1273 
1274         // Binary operations
1275 
1276         @Override
1277         @ForceInline
1278         public Short64Mask and(VectorMask<Short> o) {
1279             Objects.requireNonNull(o);
1280             Short64Mask m = (Short64Mask)o;
1281             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short64Mask.class, short.class, LENGTH,
1282                                              this, m,
1283                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1284         }
1285 
1286         @Override
1287         @ForceInline
1288         public Short64Mask or(VectorMask<Short> o) {
1289             Objects.requireNonNull(o);
1290             Short64Mask m = (Short64Mask)o;
1291             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Short64Mask.class, short.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, Short64Mask.class, short.class, LENGTH,
1302                                          this, this,
1303                                          (m, __) -> anyTrueHelper(((Short64Mask)m).getBits()));
1304         }
1305 
1306         @Override
1307         @ForceInline
1308         public boolean allTrue() {
1309             return VectorIntrinsics.test(BT_overflow, Short64Mask.class, short.class, LENGTH,
1310                                          this, VectorMask.maskAllTrue(species()),
1311                                          (m, __) -> allTrueHelper(((Short64Mask)m).getBits()));
1312         }
1313     }
1314 
1315     // Shuffle
1316 
1317     static final class Short64Shuffle extends AbstractShuffle<Short> {
1318         Short64Shuffle(byte[] reorder) {
1319             super(reorder);
1320         }
1321 
1322         public Short64Shuffle(int[] reorder) {
1323             super(reorder);
1324         }
1325 
1326         public Short64Shuffle(int[] reorder, int i) {
1327             super(reorder, i);
1328         }
1329 
1330         public Short64Shuffle(IntUnaryOperator f) {
1331             super(f);
1332         }
1333 
1334         @Override
1335         public VectorSpecies<Short> species() {
1336             return SPECIES;
1337         }
1338 
1339         @Override
1340         public ShortVector toVector() {
1341             short[] va = new short[SPECIES.length()];
1342             for (int i = 0; i < va.length; i++) {
1343               va[i] = (short) lane(i);
1344             }
1345             return ShortVector.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 Byte64Vector.Byte64Shuffle(shuffleArray);
1358             } else if (stype == short.class) {
1359                 return (VectorShuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1360             } else if (stype == int.class) {
1361                 return (VectorShuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1362             } else if (stype == long.class) {
1363                 return (VectorShuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
1364             } else if (stype == float.class) {
1365                 return (VectorShuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
1366             } else if (stype == double.class) {
1367                 return (VectorShuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
1368             } else {
1369                 throw new UnsupportedOperationException("Bad lane type for casting.");
1370             }
1371         }
1372 
1373         @Override
1374         public Short64Shuffle rearrange(VectorShuffle<Short> o) {
1375             Short64Shuffle s = (Short64Shuffle) 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 Short64Shuffle(r);
1381         }
1382     }
1383 
1384     // VectorSpecies
1385 
1386     @Override
1387     public VectorSpecies<Short> species() {
1388         return SPECIES;
1389     }
1390 }