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     @ForceInline
1060     public Short64Vector rotateLanesLeft(int j) {
1061       int L = length();
1062       if (j < 0) {
1063          throw new IllegalArgumentException("Index " + j + " must be zero or positive");
1064       } else {
1065         j = j & (L-1);
1066         VectorShuffle<Short> PermMask  = VectorShuffle.shuffleIota(SPECIES, L - j);
1067         return this.rearrange(PermMask);
1068       }
1069     }
1070 
1071     @Override
1072     @ForceInline
1073     public Short64Vector rotateLanesRight(int j) {
1074       int L = length();
1075       if (j < 0) {
1076          throw new IllegalArgumentException("Index " + j + " must be zero or positive");
1077       } else {
1078         j = j & (L-1);
1079         VectorShuffle<Short> PermMask = VectorShuffle.shuffleIota(SPECIES, j);
1080         return this.rearrange(PermMask);
1081       }
1082     }
1083 
1084     @Override
1085     @ForceInline
1086     @SuppressWarnings("unchecked")
1087     public Short64Vector shiftLanesLeft(int j) {
1088        int L = length();
1089        if (j < 0) {
1090          throw new IllegalArgumentException("Index " + j + " must be zero or positive");
1091        } else if ( j >= L ) {
1092          return ZERO;
1093        } else {
1094          Short64Shuffle     Iota    = (Short64Shuffle)(VectorShuffle.shuffleIota(SPECIES, L-j));
1095          VectorMask<Short> BlendMask = Iota.toVector().lessThan(Short64Vector.broadcast(SPECIES, (short)(L-j)));
1096          Iota    = (Short64Shuffle)(VectorShuffle.shuffleIota(SPECIES, L -j));
1097          return ZERO.blend(this.rearrange(Iota),BlendMask);
1098        }
1099     }
1100 
1101     @Override
1102     @ForceInline
1103     @SuppressWarnings("unchecked")
1104     public Short64Vector shiftLanesRight(int j) {
1105        int L = length();
1106        if (j < 0) {
1107          throw new IllegalArgumentException("Index " + j + " must be zero or positive");
1108        } else if ( j >= L ) {
1109          return ZERO;
1110        } else {
1111          Short64Shuffle     Iota    = (Short64Shuffle)(VectorShuffle.shuffleIota(SPECIES, j));
1112          VectorMask<Short> BlendMask = Iota.toVector().greaterThanEq(Short64Vector.broadcast(SPECIES, (short)(j)));
1113          Iota    = (Short64Shuffle)(VectorShuffle.shuffleIota(SPECIES, j));
1114          return ZERO.blend(this.rearrange(Iota),BlendMask);
1115        }
1116     }
1117 
1118     @Override
1119     @ForceInline
1120     public Short64Vector rearrange(Vector<Short> v,
1121                                   VectorShuffle<Short> s, VectorMask<Short> m) {
1122         return this.rearrange(s).blend(v.rearrange(s), m);
1123     }
1124 
1125     @Override
1126     @ForceInline
1127     public Short64Vector rearrange(VectorShuffle<Short> o1) {
1128         Objects.requireNonNull(o1);
1129         Short64Shuffle s =  (Short64Shuffle)o1;
1130 
1131         return VectorIntrinsics.rearrangeOp(
1132             Short64Vector.class, Short64Shuffle.class, short.class, LENGTH,
1133             this, s,
1134             (v1, s_) -> v1.uOp((i, a) -> {
1135                 int ei = s_.lane(i);
1136                 return v1.lane(ei);
1137             }));
1138     }
1139 
1140     @Override
1141     @ForceInline
1142     public Short64Vector blend(Vector<Short> o1, VectorMask<Short> o2) {
1143         Objects.requireNonNull(o1);
1144         Objects.requireNonNull(o2);
1145         Short64Vector v = (Short64Vector)o1;
1146         Short64Mask   m = (Short64Mask)o2;
1147 
1148         return VectorIntrinsics.blend(
1149             Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1150             this, v, m,
1151             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.lane(i) ? b : a));
1152     }
1153 
1154     // Accessors
1155 
1156     @Override
1157     public short lane(int i) {
1158         if (i < 0 || i >= LENGTH) {
1159             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1160         }
1161         return (short) VectorIntrinsics.extract(
1162                                 Short64Vector.class, short.class, LENGTH,
1163                                 this, i,
1164                                 (vec, ix) -> {
1165                                     short[] vecarr = vec.getElements();
1166                                     return (long)vecarr[ix];
1167                                 });
1168     }
1169 
1170     @Override
1171     public Short64Vector with(int i, short e) {
1172         if (i < 0 || i >= LENGTH) {
1173             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1174         }
1175         return VectorIntrinsics.insert(
1176                                 Short64Vector.class, short.class, LENGTH,
1177                                 this, i, (long)e,
1178                                 (v, ix, bits) -> {
1179                                     short[] res = v.getElements().clone();
1180                                     res[ix] = (short)bits;
1181                                     return new Short64Vector(res);
1182                                 });
1183     }
1184 
1185     // Mask
1186 
1187     static final class Short64Mask extends AbstractMask<Short> {
1188         static final Short64Mask TRUE_MASK = new Short64Mask(true);
1189         static final Short64Mask FALSE_MASK = new Short64Mask(false);
1190 
1191         private final boolean[] bits; // Don't access directly, use getBits() instead.
1192 
1193         public Short64Mask(boolean[] bits) {
1194             this(bits, 0);
1195         }
1196 
1197         public Short64Mask(boolean[] bits, int offset) {
1198             boolean[] a = new boolean[species().length()];
1199             for (int i = 0; i < a.length; i++) {
1200                 a[i] = bits[offset + i];
1201             }
1202             this.bits = a;
1203         }
1204 
1205         public Short64Mask(boolean val) {
1206             boolean[] bits = new boolean[species().length()];
1207             Arrays.fill(bits, val);
1208             this.bits = bits;
1209         }
1210 
1211         boolean[] getBits() {
1212             return VectorIntrinsics.maybeRebox(this).bits;
1213         }
1214 
1215         @Override
1216         Short64Mask uOp(MUnOp f) {
1217             boolean[] res = new boolean[species().length()];
1218             boolean[] bits = getBits();
1219             for (int i = 0; i < species().length(); i++) {
1220                 res[i] = f.apply(i, bits[i]);
1221             }
1222             return new Short64Mask(res);
1223         }
1224 
1225         @Override
1226         Short64Mask bOp(VectorMask<Short> o, MBinOp f) {
1227             boolean[] res = new boolean[species().length()];
1228             boolean[] bits = getBits();
1229             boolean[] mbits = ((Short64Mask)o).getBits();
1230             for (int i = 0; i < species().length(); i++) {
1231                 res[i] = f.apply(i, bits[i], mbits[i]);
1232             }
1233             return new Short64Mask(res);
1234         }
1235 
1236         @Override
1237         public VectorSpecies<Short> species() {
1238             return SPECIES;
1239         }
1240 
1241         @Override
1242         public Short64Vector toVector() {
1243             short[] res = new short[species().length()];
1244             boolean[] bits = getBits();
1245             for (int i = 0; i < species().length(); i++) {
1246                 // -1 will result in the most significant bit being set in
1247                 // addition to some or all other bits
1248                 res[i] = (short) (bits[i] ? -1 : 0);
1249             }
1250             return new Short64Vector(res);
1251         }
1252 
1253         @Override
1254         @ForceInline
1255         @SuppressWarnings("unchecked")
1256         public <E> VectorMask<E> cast(VectorSpecies<E> species) {
1257             if (length() != species.length())
1258                 throw new IllegalArgumentException("VectorMask length and species length differ");
1259             Class<?> stype = species.elementType();
1260             boolean [] maskArray = toArray();
1261             if (stype == byte.class) {
1262                 return (VectorMask <E>) new Byte64Vector.Byte64Mask(maskArray);
1263             } else if (stype == short.class) {
1264                 return (VectorMask <E>) new Short64Vector.Short64Mask(maskArray);
1265             } else if (stype == int.class) {
1266                 return (VectorMask <E>) new Int64Vector.Int64Mask(maskArray);
1267             } else if (stype == long.class) {
1268                 return (VectorMask <E>) new Long64Vector.Long64Mask(maskArray);
1269             } else if (stype == float.class) {
1270                 return (VectorMask <E>) new Float64Vector.Float64Mask(maskArray);
1271             } else if (stype == double.class) {
1272                 return (VectorMask <E>) new Double64Vector.Double64Mask(maskArray);
1273             } else {
1274                 throw new UnsupportedOperationException("Bad lane type for casting.");
1275             }
1276         }
1277 
1278         // Unary operations
1279 
1280         @Override
1281         @ForceInline
1282         public Short64Mask not() {
1283             return (Short64Mask) VectorIntrinsics.unaryOp(
1284                                              VECTOR_OP_NOT, Short64Mask.class, short.class, LENGTH,
1285                                              this,
1286                                              (m1) -> m1.uOp((i, a) -> !a));
1287         }
1288 
1289         // Binary operations
1290 
1291         @Override
1292         @ForceInline
1293         public Short64Mask and(VectorMask<Short> o) {
1294             Objects.requireNonNull(o);
1295             Short64Mask m = (Short64Mask)o;
1296             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short64Mask.class, short.class, LENGTH,
1297                                              this, m,
1298                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1299         }
1300 
1301         @Override
1302         @ForceInline
1303         public Short64Mask or(VectorMask<Short> o) {
1304             Objects.requireNonNull(o);
1305             Short64Mask m = (Short64Mask)o;
1306             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Short64Mask.class, short.class, LENGTH,
1307                                              this, m,
1308                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1309         }
1310 
1311         // Reductions
1312 
1313         @Override
1314         @ForceInline
1315         public boolean anyTrue() {
1316             return VectorIntrinsics.test(BT_ne, Short64Mask.class, short.class, LENGTH,
1317                                          this, this,
1318                                          (m, __) -> anyTrueHelper(((Short64Mask)m).getBits()));
1319         }
1320 
1321         @Override
1322         @ForceInline
1323         public boolean allTrue() {
1324             return VectorIntrinsics.test(BT_overflow, Short64Mask.class, short.class, LENGTH,
1325                                          this, VectorMask.maskAllTrue(species()),
1326                                          (m, __) -> allTrueHelper(((Short64Mask)m).getBits()));
1327         }
1328     }
1329 
1330     // Shuffle
1331 
1332     static final class Short64Shuffle extends AbstractShuffle<Short> {
1333         Short64Shuffle(byte[] reorder) {
1334             super(reorder);
1335         }
1336 
1337         public Short64Shuffle(int[] reorder) {
1338             super(reorder);
1339         }
1340 
1341         public Short64Shuffle(int[] reorder, int i) {
1342             super(reorder, i);
1343         }
1344 
1345         public Short64Shuffle(IntUnaryOperator f) {
1346             super(f);
1347         }
1348 
1349         @Override
1350         public VectorSpecies<Short> species() {
1351             return SPECIES;
1352         }
1353 
1354         private ShortVector toVector_helper() {
1355             short[] va = new short[SPECIES.length()];
1356             for (int i = 0; i < va.length; i++) {
1357               va[i] = (short) lane(i);
1358             }
1359             return ShortVector.fromArray(SPECIES, va, 0);
1360         }
1361 
1362         @Override
1363         @ForceInline
1364         public ShortVector toVector() {
1365             return VectorIntrinsics.shuffleToVector(Short64Vector.class, short.class, Short64Shuffle.class, this,
1366                                                     SPECIES.length(), 
1367                                                     (s) -> (((Short64Shuffle)(s)).toVector_helper()));
1368         }
1369 
1370         @Override
1371         @ForceInline
1372         @SuppressWarnings("unchecked")
1373         public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1374             if (length() != species.length())
1375                 throw new IllegalArgumentException("Shuffle length and species length differ");
1376             Class<?> stype = species.elementType();
1377             int [] shuffleArray = toArray();
1378             if (stype == byte.class) {
1379                 return (VectorShuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1380             } else if (stype == short.class) {
1381                 return (VectorShuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1382             } else if (stype == int.class) {
1383                 return (VectorShuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1384             } else if (stype == long.class) {
1385                 return (VectorShuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
1386             } else if (stype == float.class) {
1387                 return (VectorShuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
1388             } else if (stype == double.class) {
1389                 return (VectorShuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
1390             } else {
1391                 throw new UnsupportedOperationException("Bad lane type for casting.");
1392             }
1393         }
1394 
1395 
1396         @Override
1397         public Short64Shuffle rearrange(VectorShuffle<Short> o) {
1398             Short64Shuffle s = (Short64Shuffle) o;
1399             byte[] r = new byte[reorder.length];
1400             for (int i = 0; i < reorder.length; i++) {
1401                 r[i] = reorder[s.reorder[i]];
1402             }
1403             return new Short64Shuffle(r);
1404         }
1405     }
1406 
1407     // VectorSpecies
1408 
1409     @Override
1410     public VectorSpecies<Short> species() {
1411         return SPECIES;
1412     }
1413 }