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