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 orAll() {
 766         return (short) VectorIntrinsics.reductionCoerced(
 767             VECTOR_OP_OR, 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(Mask<Short> m) {
 775         return blend(SPECIES.broadcast((short) 0), m).orAll();
 776     }
 777 
 778     @Override
 779     @ForceInline
 780     public short xorAll() {
 781         return (short) VectorIntrinsics.reductionCoerced(
 782             VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
 783             this,
 784             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a ^ b)));
 785     }
 786 
 787     @Override
 788     @ForceInline
 789     public short xorAll(Mask<Short> m) {
 790         return blend(SPECIES.broadcast((short) 0), m).xorAll();
 791     }
 792 
 793 
 794     @Override
 795     @ForceInline
 796     public short addAll(Mask<Short> m) {
 797         return blend(SPECIES.broadcast((short) 0), m).addAll();
 798     }
 799 
 800     @Override
 801     @ForceInline
 802     public short mulAll(Mask<Short> m) {
 803         return blend(SPECIES.broadcast((short) 1), m).mulAll();
 804     }
 805 
 806     @Override
 807     @ForceInline
 808     public short minAll(Mask<Short> m) {
 809         return blend(SPECIES.broadcast(Short.MAX_VALUE), m).minAll();
 810     }
 811 
 812     @Override
 813     @ForceInline
 814     public short maxAll(Mask<Short> m) {
 815         return blend(SPECIES.broadcast(Short.MIN_VALUE), m).maxAll();
 816     }
 817 
 818     @Override
 819     @ForceInline
 820     public Shuffle<Short> toShuffle() {
 821         short[] a = toArray();
 822         int[] sa = new int[a.length];
 823         for (int i = 0; i < a.length; i++) {
 824             sa[i] = (int) a[i];
 825         }
 826         return ShortVector.shuffleFromArray(SPECIES, sa, 0);
 827     }
 828 
 829     // Memory operations
 830 
 831     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
 832     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 833 
 834     @Override
 835     @ForceInline
 836     public void intoArray(short[] a, int ix) {
 837         Objects.requireNonNull(a);
 838         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 839         VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
 840                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
 841                                this,
 842                                a, ix,
 843                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 844     }
 845 
 846     @Override
 847     @ForceInline
 848     public final void intoArray(short[] a, int ax, Mask<Short> m) {
 849         ShortVector oldVal = ShortVector.fromArray(SPECIES, a, ax);
 850         ShortVector newVal = oldVal.blend(this, m);
 851         newVal.intoArray(a, ax);
 852     }
 853 
 854     @Override
 855     @ForceInline
 856     public void intoByteArray(byte[] a, int ix) {
 857         Objects.requireNonNull(a);
 858         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 859         VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
 860                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 861                                this,
 862                                a, ix,
 863                                (c, idx, v) -> {
 864                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 865                                    ShortBuffer tb = bbc.asShortBuffer();
 866                                    v.forEach((i, e) -> tb.put(e));
 867                                });
 868     }
 869 
 870     @Override
 871     @ForceInline
 872     public final void intoByteArray(byte[] a, int ix, Mask<Short> m) {
 873         Short64Vector oldVal = (Short64Vector) ShortVector.fromByteArray(SPECIES, a, ix);
 874         Short64Vector newVal = oldVal.blend(this, m);
 875         newVal.intoByteArray(a, ix);
 876     }
 877 
 878     @Override
 879     @ForceInline
 880     public void intoByteBuffer(ByteBuffer bb, int ix) {
 881         if (bb.order() != ByteOrder.nativeOrder()) {
 882             throw new IllegalArgumentException();
 883         }
 884         if (bb.isReadOnly()) {
 885             throw new ReadOnlyBufferException();
 886         }
 887         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 888         VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
 889                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 890                                this,
 891                                bb, ix,
 892                                (c, idx, v) -> {
 893                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 894                                    ShortBuffer tb = bbc.asShortBuffer();
 895                                    v.forEach((i, e) -> tb.put(e));
 896                                });
 897     }
 898 
 899     @Override
 900     @ForceInline
 901     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m) {
 902         Short64Vector oldVal = (Short64Vector) ShortVector.fromByteBuffer(SPECIES, bb, ix);
 903         Short64Vector newVal = oldVal.blend(this, m);
 904         newVal.intoByteBuffer(bb, ix);
 905     }
 906 
 907     //
 908 
 909     @Override
 910     public String toString() {
 911         return Arrays.toString(getElements());
 912     }
 913 
 914     @Override
 915     public boolean equals(Object o) {
 916         if (this == o) return true;
 917         if (o == null || this.getClass() != o.getClass()) return false;
 918 
 919         Short64Vector that = (Short64Vector) o;
 920         return this.equal(that).allTrue();
 921     }
 922 
 923     @Override
 924     public int hashCode() {
 925         return Arrays.hashCode(vec);
 926     }
 927 
 928     // Binary test
 929 
 930     @Override
 931     Short64Mask bTest(Vector<Short> o, FBinTest f) {
 932         short[] vec1 = getElements();
 933         short[] vec2 = ((Short64Vector)o).getElements();
 934         boolean[] bits = new boolean[length()];
 935         for (int i = 0; i < length(); i++){
 936             bits[i] = f.apply(i, vec1[i], vec2[i]);
 937         }
 938         return new Short64Mask(bits);
 939     }
 940 
 941     // Comparisons
 942 
 943     @Override
 944     @ForceInline
 945     public Short64Mask equal(Vector<Short> o) {
 946         Objects.requireNonNull(o);
 947         Short64Vector v = (Short64Vector)o;
 948 
 949         return VectorIntrinsics.compare(
 950             BT_eq, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 951             this, v,
 952             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
 953     }
 954 
 955     @Override
 956     @ForceInline
 957     public Short64Mask notEqual(Vector<Short> o) {
 958         Objects.requireNonNull(o);
 959         Short64Vector v = (Short64Vector)o;
 960 
 961         return VectorIntrinsics.compare(
 962             BT_ne, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 963             this, v,
 964             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
 965     }
 966 
 967     @Override
 968     @ForceInline
 969     public Short64Mask lessThan(Vector<Short> o) {
 970         Objects.requireNonNull(o);
 971         Short64Vector v = (Short64Vector)o;
 972 
 973         return VectorIntrinsics.compare(
 974             BT_lt, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 975             this, v,
 976             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
 977     }
 978 
 979     @Override
 980     @ForceInline
 981     public Short64Mask lessThanEq(Vector<Short> o) {
 982         Objects.requireNonNull(o);
 983         Short64Vector v = (Short64Vector)o;
 984 
 985         return VectorIntrinsics.compare(
 986             BT_le, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 987             this, v,
 988             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
 989     }
 990 
 991     @Override
 992     @ForceInline
 993     public Short64Mask greaterThan(Vector<Short> o) {
 994         Objects.requireNonNull(o);
 995         Short64Vector v = (Short64Vector)o;
 996 
 997         return (Short64Mask) VectorIntrinsics.compare(
 998             BT_gt, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
 999             this, v,
1000             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1001     }
1002 
1003     @Override
1004     @ForceInline
1005     public Short64Mask greaterThanEq(Vector<Short> o) {
1006         Objects.requireNonNull(o);
1007         Short64Vector v = (Short64Vector)o;
1008 
1009         return VectorIntrinsics.compare(
1010             BT_ge, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1011             this, v,
1012             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1013     }
1014 
1015     // Foreach
1016 
1017     @Override
1018     void forEach(FUnCon f) {
1019         short[] vec = getElements();
1020         for (int i = 0; i < length(); i++) {
1021             f.apply(i, vec[i]);
1022         }
1023     }
1024 
1025     @Override
1026     void forEach(Mask<Short> o, FUnCon f) {
1027         boolean[] mbits = ((Short64Mask)o).getBits();
1028         forEach((i, a) -> {
1029             if (mbits[i]) { f.apply(i, a); }
1030         });
1031     }
1032 
1033 
1034 
1035     @Override
1036     public Short64Vector rotateEL(int j) {
1037         short[] vec = getElements();
1038         short[] res = new short[length()];
1039         for (int i = 0; i < length(); i++){
1040             res[(j + i) % length()] = vec[i];
1041         }
1042         return new Short64Vector(res);
1043     }
1044 
1045     @Override
1046     public Short64Vector rotateER(int j) {
1047         short[] vec = getElements();
1048         short[] res = new short[length()];
1049         for (int i = 0; i < length(); i++){
1050             int z = i - j;
1051             if(j < 0) {
1052                 res[length() + z] = vec[i];
1053             } else {
1054                 res[z] = vec[i];
1055             }
1056         }
1057         return new Short64Vector(res);
1058     }
1059 
1060     @Override
1061     public Short64Vector shiftEL(int j) {
1062         short[] vec = getElements();
1063         short[] res = new short[length()];
1064         for (int i = 0; i < length() - j; i++) {
1065             res[i] = vec[i + j];
1066         }
1067         return new Short64Vector(res);
1068     }
1069 
1070     @Override
1071     public Short64Vector shiftER(int j) {
1072         short[] vec = getElements();
1073         short[] res = new short[length()];
1074         for (int i = 0; i < length() - j; i++){
1075             res[i + j] = vec[i];
1076         }
1077         return new Short64Vector(res);
1078     }
1079 
1080     @Override
1081     @ForceInline
1082     public Short64Vector rearrange(Vector<Short> v,
1083                                   Shuffle<Short> s, Mask<Short> m) {
1084         return this.rearrange(s).blend(v.rearrange(s), m);
1085     }
1086 
1087     @Override
1088     @ForceInline
1089     public Short64Vector rearrange(Shuffle<Short> o1) {
1090         Objects.requireNonNull(o1);
1091         Short64Shuffle s =  (Short64Shuffle)o1;
1092 
1093         return VectorIntrinsics.rearrangeOp(
1094             Short64Vector.class, Short64Shuffle.class, short.class, LENGTH,
1095             this, s,
1096             (v1, s_) -> v1.uOp((i, a) -> {
1097                 int ei = s_.getElement(i);
1098                 return v1.get(ei);
1099             }));
1100     }
1101 
1102     @Override
1103     @ForceInline
1104     public Short64Vector blend(Vector<Short> o1, Mask<Short> o2) {
1105         Objects.requireNonNull(o1);
1106         Objects.requireNonNull(o2);
1107         Short64Vector v = (Short64Vector)o1;
1108         Short64Mask   m = (Short64Mask)o2;
1109 
1110         return VectorIntrinsics.blend(
1111             Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1112             this, v, m,
1113             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1114     }
1115 
1116     // Accessors
1117 
1118     @Override
1119     public short get(int i) {
1120         if (i < 0 || i >= LENGTH) {
1121             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1122         }
1123         return (short) VectorIntrinsics.extract(
1124                                 Short64Vector.class, short.class, LENGTH,
1125                                 this, i,
1126                                 (vec, ix) -> {
1127                                     short[] vecarr = vec.getElements();
1128                                     return (long)vecarr[ix];
1129                                 });
1130     }
1131 
1132     @Override
1133     public Short64Vector with(int i, short e) {
1134         if (i < 0 || i >= LENGTH) {
1135             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1136         }
1137         return VectorIntrinsics.insert(
1138                                 Short64Vector.class, short.class, LENGTH,
1139                                 this, i, (long)e,
1140                                 (v, ix, bits) -> {
1141                                     short[] res = v.getElements().clone();
1142                                     res[ix] = (short)bits;
1143                                     return new Short64Vector(res);
1144                                 });
1145     }
1146 
1147     // Mask
1148 
1149     static final class Short64Mask extends AbstractMask<Short> {
1150         static final Short64Mask TRUE_MASK = new Short64Mask(true);
1151         static final Short64Mask FALSE_MASK = new Short64Mask(false);
1152 
1153         private final boolean[] bits; // Don't access directly, use getBits() instead.
1154 
1155         public Short64Mask(boolean[] bits) {
1156             this(bits, 0);
1157         }
1158 
1159         public Short64Mask(boolean[] bits, int offset) {
1160             boolean[] a = new boolean[species().length()];
1161             for (int i = 0; i < a.length; i++) {
1162                 a[i] = bits[offset + i];
1163             }
1164             this.bits = a;
1165         }
1166 
1167         public Short64Mask(boolean val) {
1168             boolean[] bits = new boolean[species().length()];
1169             Arrays.fill(bits, val);
1170             this.bits = bits;
1171         }
1172 
1173         boolean[] getBits() {
1174             return VectorIntrinsics.maybeRebox(this).bits;
1175         }
1176 
1177         @Override
1178         Short64Mask uOp(MUnOp f) {
1179             boolean[] res = new boolean[species().length()];
1180             boolean[] bits = getBits();
1181             for (int i = 0; i < species().length(); i++) {
1182                 res[i] = f.apply(i, bits[i]);
1183             }
1184             return new Short64Mask(res);
1185         }
1186 
1187         @Override
1188         Short64Mask bOp(Mask<Short> o, MBinOp f) {
1189             boolean[] res = new boolean[species().length()];
1190             boolean[] bits = getBits();
1191             boolean[] mbits = ((Short64Mask)o).getBits();
1192             for (int i = 0; i < species().length(); i++) {
1193                 res[i] = f.apply(i, bits[i], mbits[i]);
1194             }
1195             return new Short64Mask(res);
1196         }
1197 
1198         @Override
1199         public Short64Species species() {
1200             return SPECIES;
1201         }
1202 
1203         @Override
1204         public Short64Vector toVector() {
1205             short[] res = new short[species().length()];
1206             boolean[] bits = getBits();
1207             for (int i = 0; i < species().length(); i++) {
1208                 // -1 will result in the most significant bit being set in
1209                 // addition to some or all other bits
1210                 res[i] = (short) (bits[i] ? -1 : 0);
1211             }
1212             return new Short64Vector(res);
1213         }
1214 
1215         // Unary operations
1216 
1217         @Override
1218         @ForceInline
1219         public Short64Mask not() {
1220             return (Short64Mask) VectorIntrinsics.unaryOp(
1221                                              VECTOR_OP_NOT, Short64Mask.class, short.class, LENGTH,
1222                                              this,
1223                                              (m1) -> m1.uOp((i, a) -> !a));
1224         }
1225 
1226         // Binary operations
1227 
1228         @Override
1229         @ForceInline
1230         public Short64Mask and(Mask<Short> o) {
1231             Objects.requireNonNull(o);
1232             Short64Mask m = (Short64Mask)o;
1233             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short64Mask.class, short.class, LENGTH,
1234                                              this, m,
1235                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1236         }
1237 
1238         @Override
1239         @ForceInline
1240         public Short64Mask or(Mask<Short> o) {
1241             Objects.requireNonNull(o);
1242             Short64Mask m = (Short64Mask)o;
1243             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Short64Mask.class, short.class, LENGTH,
1244                                              this, m,
1245                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1246         }
1247 
1248         // Reductions
1249 
1250         @Override
1251         @ForceInline
1252         public boolean anyTrue() {
1253             return VectorIntrinsics.test(BT_ne, Short64Mask.class, short.class, LENGTH,
1254                                          this, this,
1255                                          (m, __) -> anyTrueHelper(((Short64Mask)m).getBits()));
1256         }
1257 
1258         @Override
1259         @ForceInline
1260         public boolean allTrue() {
1261             return VectorIntrinsics.test(BT_overflow, Short64Mask.class, short.class, LENGTH,
1262                                          this, ShortVector.maskAllTrue(species()),
1263                                          (m, __) -> allTrueHelper(((Short64Mask)m).getBits()));
1264         }
1265     }
1266 
1267     // Shuffle
1268 
1269     static final class Short64Shuffle extends AbstractShuffle<Short> {
1270         Short64Shuffle(byte[] reorder) {
1271             super(reorder);
1272         }
1273 
1274         public Short64Shuffle(int[] reorder) {
1275             super(reorder);
1276         }
1277 
1278         public Short64Shuffle(int[] reorder, int i) {
1279             super(reorder, i);
1280         }
1281 
1282         public Short64Shuffle(IntUnaryOperator f) {
1283             super(f);
1284         }
1285 
1286         @Override
1287         public Short64Species species() {
1288             return SPECIES;
1289         }
1290 
1291         @Override
1292         public ShortVector toVector() {
1293             short[] va = new short[SPECIES.length()];
1294             for (int i = 0; i < va.length; i++) {
1295               va[i] = (short) getElement(i);
1296             }
1297             return ShortVector.fromArray(SPECIES, va, 0);
1298         }
1299 
1300         @Override
1301         public Short64Shuffle rearrange(Vector.Shuffle<Short> o) {
1302             Short64Shuffle s = (Short64Shuffle) o;
1303             byte[] r = new byte[reorder.length];
1304             for (int i = 0; i < reorder.length; i++) {
1305                 r[i] = reorder[s.reorder[i]];
1306             }
1307             return new Short64Shuffle(r);
1308         }
1309     }
1310 
1311     // Species
1312 
1313     @Override
1314     public Short64Species species() {
1315         return SPECIES;
1316     }
1317 
1318     static final class Short64Species extends ShortSpecies {
1319         static final int BIT_SIZE = Shape.S_64_BIT.bitSize();
1320 
1321         static final int LENGTH = BIT_SIZE / Short.SIZE;
1322 
1323         @Override
1324         public String toString() {
1325            StringBuilder sb = new StringBuilder("Shape[");
1326            sb.append(bitSize()).append(" bits, ");
1327            sb.append(length()).append(" ").append(short.class.getSimpleName()).append("s x ");
1328            sb.append(elementSize()).append(" bits");
1329            sb.append("]");
1330            return sb.toString();
1331         }
1332 
1333         @Override
1334         @ForceInline
1335         public int bitSize() {
1336             return BIT_SIZE;
1337         }
1338 
1339         @Override
1340         @ForceInline
1341         public int length() {
1342             return LENGTH;
1343         }
1344 
1345         @Override
1346         @ForceInline
1347         public Class<Short> elementType() {
1348             return short.class;
1349         }
1350 
1351         @Override
1352         @ForceInline
1353         public Class<?> boxType() {
1354             return Short64Vector.class;
1355         }
1356 
1357         @Override
1358         @ForceInline
1359         public Class<?> maskType() {
1360             return Short64Mask.class;
1361         }
1362 
1363         @Override
1364         @ForceInline
1365         public int elementSize() {
1366             return Short.SIZE;
1367         }
1368 
1369         @Override
1370         @ForceInline
1371         @SuppressWarnings("unchecked")
1372         Class<?> vectorType() {
1373             return Short64Vector.class;
1374         }
1375 
1376         @Override
1377         @ForceInline
1378         public Shape shape() {
1379             return Shape.S_64_BIT;
1380         }
1381 
1382         @Override
1383         Short64Vector op(FOp f) {
1384             short[] res = new short[length()];
1385             for (int i = 0; i < length(); i++) {
1386                 res[i] = f.apply(i);
1387             }
1388             return new Short64Vector(res);
1389         }
1390 
1391         @Override
1392         Short64Vector op(Mask<Short> o, FOp f) {
1393             short[] res = new short[length()];
1394             boolean[] mbits = ((Short64Mask)o).getBits();
1395             for (int i = 0; i < length(); i++) {
1396                 if (mbits[i]) {
1397                     res[i] = f.apply(i);
1398                 }
1399             }
1400             return new Short64Vector(res);
1401         }
1402 
1403         @Override
1404         Short64Mask opm(FOpm f) {
1405             boolean[] res = new boolean[length()];
1406             for (int i = 0; i < length(); i++) {
1407                 res[i] = (boolean)f.apply(i);
1408             }
1409             return new Short64Mask(res);
1410         }
1411 
1412         // Factories
1413 
1414         @Override
1415         @ForceInline
1416         public Short64Vector zero() {
1417             return VectorIntrinsics.broadcastCoerced(Short64Vector.class, short.class, LENGTH,
1418                                                      0, SPECIES,
1419                                                      ((bits, s) -> ((Short64Species)s).op(i -> (short)bits)));
1420         }
1421 
1422         @Override
1423         @ForceInline
1424         public Short64Vector broadcast(short e) {
1425             return VectorIntrinsics.broadcastCoerced(
1426                 Short64Vector.class, short.class, LENGTH,
1427                 e, SPECIES,
1428                 ((bits, s) -> ((Short64Species)s).op(i -> (short)bits)));
1429         }
1430 
1431         @Override
1432         @ForceInline
1433         public Short64Vector scalars(short... es) {
1434             Objects.requireNonNull(es);
1435             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1436             return VectorIntrinsics.load(Short64Vector.class, short.class, LENGTH,
1437                                          es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
1438                                          es, ix, SPECIES,
1439                                          (c, idx, s) -> ((Short64Species)s).op(n -> c[idx + n]));
1440         }
1441 
1442         @Override
1443         @ForceInline
1444         public <E> Short64Mask cast(Mask<E> m) {
1445             if (m.length() != LENGTH)
1446                 throw new IllegalArgumentException("Mask length this species length differ");
1447             return new Short64Mask(m.toArray());
1448         }
1449 
1450         @Override
1451         @ForceInline
1452         public <E> Short64Shuffle cast(Shuffle<E> s) {
1453             if (s.length() != LENGTH)
1454                 throw new IllegalArgumentException("Shuffle length this species length differ");
1455             return new Short64Shuffle(s.toArray());
1456         }
1457     }
1458 }