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 ShortMaxVector extends ShortVector {
  41     static final ShortMaxSpecies SPECIES = new ShortMaxSpecies();
  42 
  43     static final ShortMaxVector ZERO = new ShortMaxVector();
  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     ShortMaxVector() {
  54         vec = new short[SPECIES.length()];
  55     }
  56 
  57     ShortMaxVector(short[] v) {
  58         vec = v;
  59     }
  60 
  61     @Override
  62     public int length() { return LENGTH; }
  63 
  64     // Unary operator
  65 
  66     @Override
  67     ShortMaxVector 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 ShortMaxVector(res);
  74     }
  75 
  76     @Override
  77     ShortMaxVector uOp(Mask<Short> o, FUnOp f) {
  78         short[] vec = getElements();
  79         short[] res = new short[length()];
  80         boolean[] mbits = ((ShortMaxMask)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 ShortMaxVector(res);
  85     }
  86 
  87     // Binary operator
  88 
  89     @Override
  90     ShortMaxVector bOp(Vector<Short> o, FBinOp f) {
  91         short[] res = new short[length()];
  92         short[] vec1 = this.getElements();
  93         short[] vec2 = ((ShortMaxVector)o).getElements();
  94         for (int i = 0; i < length(); i++) {
  95             res[i] = f.apply(i, vec1[i], vec2[i]);
  96         }
  97         return new ShortMaxVector(res);
  98     }
  99 
 100     @Override
 101     ShortMaxVector bOp(Vector<Short> o1, Mask<Short> o2, FBinOp f) {
 102         short[] res = new short[length()];
 103         short[] vec1 = this.getElements();
 104         short[] vec2 = ((ShortMaxVector)o1).getElements();
 105         boolean[] mbits = ((ShortMaxMask)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 ShortMaxVector(res);
 110     }
 111 
 112     // Trinary operator
 113 
 114     @Override
 115     ShortMaxVector tOp(Vector<Short> o1, Vector<Short> o2, FTriOp f) {
 116         short[] res = new short[length()];
 117         short[] vec1 = this.getElements();
 118         short[] vec2 = ((ShortMaxVector)o1).getElements();
 119         short[] vec3 = ((ShortMaxVector)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 ShortMaxVector(res);
 124     }
 125 
 126     @Override
 127     ShortMaxVector 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 = ((ShortMaxVector)o1).getElements();
 131         short[] vec3 = ((ShortMaxVector)o2).getElements();
 132         boolean[] mbits = ((ShortMaxMask)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 ShortMaxVector(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             ShortMaxVector.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                 ShortMaxVector.class,
 236                 short.class, LENGTH,
 237                 ByteMaxVector.class,
 238                 byte.class, ByteMaxVector.LENGTH,
 239                 this, s,
 240                 (species, vector) -> vector.defaultReinterpret(species)
 241             );
 242         } else if (stype == short.class) {
 243             return VectorIntrinsics.reinterpret(
 244                 ShortMaxVector.class,
 245                 short.class, LENGTH,
 246                 ShortMaxVector.class,
 247                 short.class, ShortMaxVector.LENGTH,
 248                 this, s,
 249                 (species, vector) -> vector.defaultReinterpret(species)
 250             );
 251         } else if (stype == int.class) {
 252             return VectorIntrinsics.reinterpret(
 253                 ShortMaxVector.class,
 254                 short.class, LENGTH,
 255                 IntMaxVector.class,
 256                 int.class, IntMaxVector.LENGTH,
 257                 this, s,
 258                 (species, vector) -> vector.defaultReinterpret(species)
 259             );
 260         } else if (stype == long.class) {
 261             return VectorIntrinsics.reinterpret(
 262                 ShortMaxVector.class,
 263                 short.class, LENGTH,
 264                 LongMaxVector.class,
 265                 long.class, LongMaxVector.LENGTH,
 266                 this, s,
 267                 (species, vector) -> vector.defaultReinterpret(species)
 268             );
 269         } else if (stype == float.class) {
 270             return VectorIntrinsics.reinterpret(
 271                 ShortMaxVector.class,
 272                 short.class, LENGTH,
 273                 FloatMaxVector.class,
 274                 float.class, FloatMaxVector.LENGTH,
 275                 this, s,
 276                 (species, vector) -> vector.defaultReinterpret(species)
 277             );
 278         } else if (stype == double.class) {
 279             return VectorIntrinsics.reinterpret(
 280                 ShortMaxVector.class,
 281                 short.class, LENGTH,
 282                 DoubleMaxVector.class,
 283                 double.class, DoubleMaxVector.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                 ShortMaxVector.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                 ShortMaxVector.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                 ShortMaxVector.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                 ShortMaxVector.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                 ShortMaxVector.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 ShortMaxVector neg() {
 484         return (ShortMaxVector)zero(SPECIES).sub(this);
 485     }
 486 
 487     // Unary operations
 488 
 489     @ForceInline
 490     @Override
 491     public ShortMaxVector neg(Mask<Short> m) {
 492         return blend(neg(), m);
 493     }
 494 
 495     @Override
 496     @ForceInline
 497     public ShortMaxVector abs() {
 498         return VectorIntrinsics.unaryOp(
 499             VECTOR_OP_ABS, ShortMaxVector.class, short.class, LENGTH,
 500             this,
 501             v1 -> v1.uOp((i, a) -> (short) Math.abs(a)));
 502     }
 503 
 504     @ForceInline
 505     @Override
 506     public ShortMaxVector abs(Mask<Short> m) {
 507         return blend(abs(), m);
 508     }
 509 
 510 
 511     @Override
 512     @ForceInline
 513     public ShortMaxVector not() {
 514         return VectorIntrinsics.unaryOp(
 515             VECTOR_OP_NOT, ShortMaxVector.class, short.class, LENGTH,
 516             this,
 517             v1 -> v1.uOp((i, a) -> (short) ~a));
 518     }
 519 
 520     @ForceInline
 521     @Override
 522     public ShortMaxVector not(Mask<Short> m) {
 523         return blend(not(), m);
 524     }
 525     // Binary operations
 526 
 527     @Override
 528     @ForceInline
 529     public ShortMaxVector add(Vector<Short> o) {
 530         Objects.requireNonNull(o);
 531         ShortMaxVector v = (ShortMaxVector)o;
 532         return VectorIntrinsics.binaryOp(
 533             VECTOR_OP_ADD, ShortMaxVector.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 ShortMaxVector add(Vector<Short> v, Mask<Short> m) {
 541         return blend(add(v), m);
 542     }
 543 
 544     @Override
 545     @ForceInline
 546     public ShortMaxVector sub(Vector<Short> o) {
 547         Objects.requireNonNull(o);
 548         ShortMaxVector v = (ShortMaxVector)o;
 549         return VectorIntrinsics.binaryOp(
 550             VECTOR_OP_SUB, ShortMaxVector.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 ShortMaxVector sub(Vector<Short> v, Mask<Short> m) {
 558         return blend(sub(v), m);
 559     }
 560 
 561     @Override
 562     @ForceInline
 563     public ShortMaxVector mul(Vector<Short> o) {
 564         Objects.requireNonNull(o);
 565         ShortMaxVector v = (ShortMaxVector)o;
 566         return VectorIntrinsics.binaryOp(
 567             VECTOR_OP_MUL, ShortMaxVector.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 ShortMaxVector mul(Vector<Short> v, Mask<Short> m) {
 575         return blend(mul(v), m);
 576     }
 577 
 578     @Override
 579     @ForceInline
 580     public ShortMaxVector min(Vector<Short> o) {
 581         Objects.requireNonNull(o);
 582         ShortMaxVector v = (ShortMaxVector)o;
 583         return (ShortMaxVector) VectorIntrinsics.binaryOp(
 584             VECTOR_OP_MIN, ShortMaxVector.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 ShortMaxVector min(Vector<Short> v, Mask<Short> m) {
 592         return blend(min(v), m);
 593     }
 594 
 595     @Override
 596     @ForceInline
 597     public ShortMaxVector max(Vector<Short> o) {
 598         Objects.requireNonNull(o);
 599         ShortMaxVector v = (ShortMaxVector)o;
 600         return VectorIntrinsics.binaryOp(
 601             VECTOR_OP_MAX, ShortMaxVector.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 ShortMaxVector max(Vector<Short> v, Mask<Short> m) {
 609         return blend(max(v), m);
 610     }
 611 
 612     @Override
 613     @ForceInline
 614     public ShortMaxVector and(Vector<Short> o) {
 615         Objects.requireNonNull(o);
 616         ShortMaxVector v = (ShortMaxVector)o;
 617         return VectorIntrinsics.binaryOp(
 618             VECTOR_OP_AND, ShortMaxVector.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 ShortMaxVector or(Vector<Short> o) {
 626         Objects.requireNonNull(o);
 627         ShortMaxVector v = (ShortMaxVector)o;
 628         return VectorIntrinsics.binaryOp(
 629             VECTOR_OP_OR, ShortMaxVector.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 ShortMaxVector xor(Vector<Short> o) {
 637         Objects.requireNonNull(o);
 638         ShortMaxVector v = (ShortMaxVector)o;
 639         return VectorIntrinsics.binaryOp(
 640             VECTOR_OP_XOR, ShortMaxVector.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 ShortMaxVector and(Vector<Short> v, Mask<Short> m) {
 648         return blend(and(v), m);
 649     }
 650 
 651     @Override
 652     @ForceInline
 653     public ShortMaxVector or(Vector<Short> v, Mask<Short> m) {
 654         return blend(or(v), m);
 655     }
 656 
 657     @Override
 658     @ForceInline
 659     public ShortMaxVector xor(Vector<Short> v, Mask<Short> m) {
 660         return blend(xor(v), m);
 661     }
 662 
 663     @Override
 664     @ForceInline
 665     public ShortMaxVector shiftL(int s) {
 666         return VectorIntrinsics.broadcastInt(
 667             VECTOR_OP_LSHIFT, ShortMaxVector.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 ShortMaxVector shiftL(int s, Mask<Short> m) {
 675         return blend(shiftL(s), m);
 676     }
 677 
 678     @Override
 679     @ForceInline
 680     public ShortMaxVector shiftR(int s) {
 681         return VectorIntrinsics.broadcastInt(
 682             VECTOR_OP_URSHIFT, ShortMaxVector.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 ShortMaxVector shiftR(int s, Mask<Short> m) {
 690         return blend(shiftR(s), m);
 691     }
 692 
 693     @Override
 694     @ForceInline
 695     public ShortMaxVector aShiftR(int s) {
 696         return VectorIntrinsics.broadcastInt(
 697             VECTOR_OP_RSHIFT, ShortMaxVector.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 ShortMaxVector 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, ShortMaxVector.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, ShortMaxVector.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 SPECIES.broadcast((short) -1).blend(this, m).andAll();
 734     }
 735 
 736     @Override
 737     @ForceInline
 738     public short minAll() {
 739         return (short) VectorIntrinsics.reductionCoerced(
 740             VECTOR_OP_MIN, ShortMaxVector.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, ShortMaxVector.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, ShortMaxVector.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, ShortMaxVector.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 SPECIES.broadcast((short) 0).blend(this, m).orAll();
 776     }
 777 
 778     @Override
 779     @ForceInline
 780     public short xorAll() {
 781         return (short) VectorIntrinsics.reductionCoerced(
 782             VECTOR_OP_XOR, ShortMaxVector.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 SPECIES.broadcast((short) 0).blend(this, m).xorAll();
 791     }
 792 
 793 
 794     @Override
 795     @ForceInline
 796     public short addAll(Mask<Short> m) {
 797         return SPECIES.broadcast((short) 0).blend(this, m).addAll();
 798     }
 799 
 800 
 801     @Override
 802     @ForceInline
 803     public short mulAll(Mask<Short> m) {
 804         return SPECIES.broadcast((short) 1).blend(this, m).mulAll();
 805     }
 806 
 807     @Override
 808     @ForceInline
 809     public short minAll(Mask<Short> m) {
 810         return SPECIES.broadcast(Short.MAX_VALUE).blend(this, m).minAll();
 811     }
 812 
 813     @Override
 814     @ForceInline
 815     public short maxAll(Mask<Short> m) {
 816         return SPECIES.broadcast(Short.MIN_VALUE).blend(this, m).maxAll();
 817     }
 818 
 819     @Override
 820     @ForceInline
 821     public Shuffle<Short> toShuffle() {
 822         short[] a = toArray();
 823         int[] sa = new int[a.length];
 824         for (int i = 0; i < a.length; i++) {
 825             sa[i] = (int) a[i];
 826         }
 827         return ShortVector.shuffleFromArray(SPECIES, sa, 0);
 828     }
 829 
 830     // Memory operations
 831 
 832     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
 833     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 834 
 835     @Override
 836     @ForceInline
 837     public void intoArray(short[] a, int ix) {
 838         Objects.requireNonNull(a);
 839         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 840         VectorIntrinsics.store(ShortMaxVector.class, short.class, LENGTH,
 841                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
 842                                this,
 843                                a, ix,
 844                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 845     }
 846 
 847     @Override
 848     @ForceInline
 849     public final void intoArray(short[] a, int ax, Mask<Short> m) {
 850         ShortVector oldVal = ShortVector.fromArray(SPECIES, a, ax);
 851         ShortVector newVal = oldVal.blend(this, m);
 852         newVal.intoArray(a, ax);
 853     }
 854 
 855     @Override
 856     @ForceInline
 857     public void intoByteArray(byte[] a, int ix) {
 858         Objects.requireNonNull(a);
 859         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 860         VectorIntrinsics.store(ShortMaxVector.class, short.class, LENGTH,
 861                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 862                                this,
 863                                a, ix,
 864                                (c, idx, v) -> {
 865                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 866                                    ShortBuffer tb = bbc.asShortBuffer();
 867                                    v.forEach((i, e) -> tb.put(e));
 868                                });
 869     }
 870 
 871     @Override
 872     @ForceInline
 873     public final void intoByteArray(byte[] a, int ix, Mask<Short> m) {
 874         ShortMaxVector oldVal = (ShortMaxVector) ShortVector.fromByteArray(SPECIES, a, ix);
 875         ShortMaxVector newVal = oldVal.blend(this, m);
 876         newVal.intoByteArray(a, ix);
 877     }
 878 
 879     @Override
 880     @ForceInline
 881     public void intoByteBuffer(ByteBuffer bb, int ix) {
 882         if (bb.order() != ByteOrder.nativeOrder()) {
 883             throw new IllegalArgumentException();
 884         }
 885         if (bb.isReadOnly()) {
 886             throw new ReadOnlyBufferException();
 887         }
 888         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 889         VectorIntrinsics.store(ShortMaxVector.class, short.class, LENGTH,
 890                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 891                                this,
 892                                bb, ix,
 893                                (c, idx, v) -> {
 894                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 895                                    ShortBuffer tb = bbc.asShortBuffer();
 896                                    v.forEach((i, e) -> tb.put(e));
 897                                });
 898     }
 899 
 900     @Override
 901     @ForceInline
 902     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m) {
 903         ShortMaxVector oldVal = (ShortMaxVector) ShortVector.fromByteBuffer(SPECIES, bb, ix);
 904         ShortMaxVector newVal = oldVal.blend(this, m);
 905         newVal.intoByteBuffer(bb, ix);
 906     }
 907 
 908     //
 909 
 910     @Override
 911     public String toString() {
 912         return Arrays.toString(getElements());
 913     }
 914 
 915     @Override
 916     public boolean equals(Object o) {
 917         if (this == o) return true;
 918         if (o == null || this.getClass() != o.getClass()) return false;
 919 
 920         ShortMaxVector that = (ShortMaxVector) o;
 921         return this.equal(that).allTrue();
 922     }
 923 
 924     @Override
 925     public int hashCode() {
 926         return Arrays.hashCode(vec);
 927     }
 928 
 929     // Binary test
 930 
 931     @Override
 932     ShortMaxMask bTest(Vector<Short> o, FBinTest f) {
 933         short[] vec1 = getElements();
 934         short[] vec2 = ((ShortMaxVector)o).getElements();
 935         boolean[] bits = new boolean[length()];
 936         for (int i = 0; i < length(); i++){
 937             bits[i] = f.apply(i, vec1[i], vec2[i]);
 938         }
 939         return new ShortMaxMask(bits);
 940     }
 941 
 942     // Comparisons
 943 
 944     @Override
 945     @ForceInline
 946     public ShortMaxMask equal(Vector<Short> o) {
 947         Objects.requireNonNull(o);
 948         ShortMaxVector v = (ShortMaxVector)o;
 949 
 950         return VectorIntrinsics.compare(
 951             BT_eq, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 952             this, v,
 953             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
 954     }
 955 
 956     @Override
 957     @ForceInline
 958     public ShortMaxMask notEqual(Vector<Short> o) {
 959         Objects.requireNonNull(o);
 960         ShortMaxVector v = (ShortMaxVector)o;
 961 
 962         return VectorIntrinsics.compare(
 963             BT_ne, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 964             this, v,
 965             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
 966     }
 967 
 968     @Override
 969     @ForceInline
 970     public ShortMaxMask lessThan(Vector<Short> o) {
 971         Objects.requireNonNull(o);
 972         ShortMaxVector v = (ShortMaxVector)o;
 973 
 974         return VectorIntrinsics.compare(
 975             BT_lt, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 976             this, v,
 977             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
 978     }
 979 
 980     @Override
 981     @ForceInline
 982     public ShortMaxMask lessThanEq(Vector<Short> o) {
 983         Objects.requireNonNull(o);
 984         ShortMaxVector v = (ShortMaxVector)o;
 985 
 986         return VectorIntrinsics.compare(
 987             BT_le, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
 988             this, v,
 989             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
 990     }
 991 
 992     @Override
 993     @ForceInline
 994     public ShortMaxMask greaterThan(Vector<Short> o) {
 995         Objects.requireNonNull(o);
 996         ShortMaxVector v = (ShortMaxVector)o;
 997 
 998         return (ShortMaxMask) VectorIntrinsics.compare(
 999             BT_gt, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
1000             this, v,
1001             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1002     }
1003 
1004     @Override
1005     @ForceInline
1006     public ShortMaxMask greaterThanEq(Vector<Short> o) {
1007         Objects.requireNonNull(o);
1008         ShortMaxVector v = (ShortMaxVector)o;
1009 
1010         return VectorIntrinsics.compare(
1011             BT_ge, ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
1012             this, v,
1013             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1014     }
1015 
1016     // Foreach
1017 
1018     @Override
1019     void forEach(FUnCon f) {
1020         short[] vec = getElements();
1021         for (int i = 0; i < length(); i++) {
1022             f.apply(i, vec[i]);
1023         }
1024     }
1025 
1026     @Override
1027     void forEach(Mask<Short> o, FUnCon f) {
1028         boolean[] mbits = ((ShortMaxMask)o).getBits();
1029         forEach((i, a) -> {
1030             if (mbits[i]) { f.apply(i, a); }
1031         });
1032     }
1033 
1034 
1035 
1036     @Override
1037     public ShortMaxVector rotateEL(int j) {
1038         short[] vec = getElements();
1039         short[] res = new short[length()];
1040         for (int i = 0; i < length(); i++){
1041             res[(j + i) % length()] = vec[i];
1042         }
1043         return new ShortMaxVector(res);
1044     }
1045 
1046     @Override
1047     public ShortMaxVector rotateER(int j) {
1048         short[] vec = getElements();
1049         short[] res = new short[length()];
1050         for (int i = 0; i < length(); i++){
1051             int z = i - j;
1052             if(j < 0) {
1053                 res[length() + z] = vec[i];
1054             } else {
1055                 res[z] = vec[i];
1056             }
1057         }
1058         return new ShortMaxVector(res);
1059     }
1060 
1061     @Override
1062     public ShortMaxVector shiftEL(int j) {
1063         short[] vec = getElements();
1064         short[] res = new short[length()];
1065         for (int i = 0; i < length() - j; i++) {
1066             res[i] = vec[i + j];
1067         }
1068         return new ShortMaxVector(res);
1069     }
1070 
1071     @Override
1072     public ShortMaxVector shiftER(int j) {
1073         short[] vec = getElements();
1074         short[] res = new short[length()];
1075         for (int i = 0; i < length() - j; i++){
1076             res[i + j] = vec[i];
1077         }
1078         return new ShortMaxVector(res);
1079     }
1080 
1081     @Override
1082     @ForceInline
1083     public ShortMaxVector rearrange(Vector<Short> v,
1084                                   Shuffle<Short> s, Mask<Short> m) {
1085         return this.rearrange(s).blend(v.rearrange(s), m);
1086     }
1087 
1088     @Override
1089     @ForceInline
1090     public ShortMaxVector rearrange(Shuffle<Short> o1) {
1091         Objects.requireNonNull(o1);
1092         ShortMaxShuffle s =  (ShortMaxShuffle)o1;
1093 
1094         return VectorIntrinsics.rearrangeOp(
1095             ShortMaxVector.class, ShortMaxShuffle.class, short.class, LENGTH,
1096             this, s,
1097             (v1, s_) -> v1.uOp((i, a) -> {
1098                 int ei = s_.getElement(i);
1099                 return v1.get(ei);
1100             }));
1101     }
1102 
1103     @Override
1104     @ForceInline
1105     public ShortMaxVector blend(Vector<Short> o1, Mask<Short> o2) {
1106         Objects.requireNonNull(o1);
1107         Objects.requireNonNull(o2);
1108         ShortMaxVector v = (ShortMaxVector)o1;
1109         ShortMaxMask   m = (ShortMaxMask)o2;
1110 
1111         return VectorIntrinsics.blend(
1112             ShortMaxVector.class, ShortMaxMask.class, short.class, LENGTH,
1113             this, v, m,
1114             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1115     }
1116 
1117     // Accessors
1118 
1119     @Override
1120     public short get(int i) {
1121         if (i < 0 || i >= LENGTH) {
1122             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1123         }
1124         return (short) VectorIntrinsics.extract(
1125                                 ShortMaxVector.class, short.class, LENGTH,
1126                                 this, i,
1127                                 (vec, ix) -> {
1128                                     short[] vecarr = vec.getElements();
1129                                     return (long)vecarr[ix];
1130                                 });
1131     }
1132 
1133     @Override
1134     public ShortMaxVector with(int i, short e) {
1135         if (i < 0 || i >= LENGTH) {
1136             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1137         }
1138         return VectorIntrinsics.insert(
1139                                 ShortMaxVector.class, short.class, LENGTH,
1140                                 this, i, (long)e,
1141                                 (v, ix, bits) -> {
1142                                     short[] res = v.getElements().clone();
1143                                     res[ix] = (short)bits;
1144                                     return new ShortMaxVector(res);
1145                                 });
1146     }
1147 
1148     // Mask
1149 
1150     static final class ShortMaxMask extends AbstractMask<Short> {
1151         static final ShortMaxMask TRUE_MASK = new ShortMaxMask(true);
1152         static final ShortMaxMask FALSE_MASK = new ShortMaxMask(false);
1153 
1154         private final boolean[] bits; // Don't access directly, use getBits() instead.
1155 
1156         public ShortMaxMask(boolean[] bits) {
1157             this(bits, 0);
1158         }
1159 
1160         public ShortMaxMask(boolean[] bits, int offset) {
1161             boolean[] a = new boolean[species().length()];
1162             for (int i = 0; i < a.length; i++) {
1163                 a[i] = bits[offset + i];
1164             }
1165             this.bits = a;
1166         }
1167 
1168         public ShortMaxMask(boolean val) {
1169             boolean[] bits = new boolean[species().length()];
1170             Arrays.fill(bits, val);
1171             this.bits = bits;
1172         }
1173 
1174         boolean[] getBits() {
1175             return VectorIntrinsics.maybeRebox(this).bits;
1176         }
1177 
1178         @Override
1179         ShortMaxMask uOp(MUnOp f) {
1180             boolean[] res = new boolean[species().length()];
1181             boolean[] bits = getBits();
1182             for (int i = 0; i < species().length(); i++) {
1183                 res[i] = f.apply(i, bits[i]);
1184             }
1185             return new ShortMaxMask(res);
1186         }
1187 
1188         @Override
1189         ShortMaxMask bOp(Mask<Short> o, MBinOp f) {
1190             boolean[] res = new boolean[species().length()];
1191             boolean[] bits = getBits();
1192             boolean[] mbits = ((ShortMaxMask)o).getBits();
1193             for (int i = 0; i < species().length(); i++) {
1194                 res[i] = f.apply(i, bits[i], mbits[i]);
1195             }
1196             return new ShortMaxMask(res);
1197         }
1198 
1199         @Override
1200         public ShortMaxSpecies species() {
1201             return SPECIES;
1202         }
1203 
1204         @Override
1205         public ShortMaxVector toVector() {
1206             short[] res = new short[species().length()];
1207             boolean[] bits = getBits();
1208             for (int i = 0; i < species().length(); i++) {
1209                 // -1 will result in the most significant bit being set in
1210                 // addition to some or all other bits
1211                 res[i] = (short) (bits[i] ? -1 : 0);
1212             }
1213             return new ShortMaxVector(res);
1214         }
1215 
1216         // Unary operations
1217 
1218         @Override
1219         @ForceInline
1220         public ShortMaxMask not() {
1221             return (ShortMaxMask) VectorIntrinsics.unaryOp(
1222                                              VECTOR_OP_NOT, ShortMaxMask.class, short.class, LENGTH,
1223                                              this,
1224                                              (m1) -> m1.uOp((i, a) -> !a));
1225         }
1226 
1227         // Binary operations
1228 
1229         @Override
1230         @ForceInline
1231         public ShortMaxMask and(Mask<Short> o) {
1232             Objects.requireNonNull(o);
1233             ShortMaxMask m = (ShortMaxMask)o;
1234             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, ShortMaxMask.class, short.class, LENGTH,
1235                                              this, m,
1236                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1237         }
1238 
1239         @Override
1240         @ForceInline
1241         public ShortMaxMask or(Mask<Short> o) {
1242             Objects.requireNonNull(o);
1243             ShortMaxMask m = (ShortMaxMask)o;
1244             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, ShortMaxMask.class, short.class, LENGTH,
1245                                              this, m,
1246                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1247         }
1248 
1249         // Reductions
1250 
1251         @Override
1252         @ForceInline
1253         public boolean anyTrue() {
1254             return VectorIntrinsics.test(BT_ne, ShortMaxMask.class, short.class, LENGTH,
1255                                          this, this,
1256                                          (m, __) -> anyTrueHelper(((ShortMaxMask)m).getBits()));
1257         }
1258 
1259         @Override
1260         @ForceInline
1261         public boolean allTrue() {
1262             return VectorIntrinsics.test(BT_overflow, ShortMaxMask.class, short.class, LENGTH,
1263                                          this, ShortVector.maskAllTrue(species()),
1264                                          (m, __) -> allTrueHelper(((ShortMaxMask)m).getBits()));
1265         }
1266     }
1267 
1268     // Shuffle
1269 
1270     static final class ShortMaxShuffle extends AbstractShuffle<Short> {
1271         ShortMaxShuffle(byte[] reorder) {
1272             super(reorder);
1273         }
1274 
1275         public ShortMaxShuffle(int[] reorder) {
1276             super(reorder);
1277         }
1278 
1279         public ShortMaxShuffle(int[] reorder, int i) {
1280             super(reorder, i);
1281         }
1282 
1283         public ShortMaxShuffle(IntUnaryOperator f) {
1284             super(f);
1285         }
1286 
1287         @Override
1288         public ShortMaxSpecies species() {
1289             return SPECIES;
1290         }
1291 
1292         @Override
1293         public ShortVector toVector() {
1294             short[] va = new short[SPECIES.length()];
1295             for (int i = 0; i < va.length; i++) {
1296               va[i] = (short) getElement(i);
1297             }
1298             return ShortVector.fromArray(SPECIES, va, 0);
1299         }
1300 
1301         @Override
1302         public ShortMaxShuffle rearrange(Vector.Shuffle<Short> o) {
1303             ShortMaxShuffle s = (ShortMaxShuffle) o;
1304             byte[] r = new byte[reorder.length];
1305             for (int i = 0; i < reorder.length; i++) {
1306                 r[i] = reorder[s.reorder[i]];
1307             }
1308             return new ShortMaxShuffle(r);
1309         }
1310     }
1311 
1312     // Species
1313 
1314     @Override
1315     public ShortMaxSpecies species() {
1316         return SPECIES;
1317     }
1318 
1319     static final class ShortMaxSpecies extends ShortSpecies {
1320         static final int BIT_SIZE = Shape.S_Max_BIT.bitSize();
1321 
1322         static final int LENGTH = BIT_SIZE / Short.SIZE;
1323 
1324         @Override
1325         public String toString() {
1326            StringBuilder sb = new StringBuilder("Shape[");
1327            sb.append(bitSize()).append(" bits, ");
1328            sb.append(length()).append(" ").append(short.class.getSimpleName()).append("s x ");
1329            sb.append(elementSize()).append(" bits");
1330            sb.append("]");
1331            return sb.toString();
1332         }
1333 
1334         @Override
1335         @ForceInline
1336         public int bitSize() {
1337             return BIT_SIZE;
1338         }
1339 
1340         @Override
1341         @ForceInline
1342         public int length() {
1343             return LENGTH;
1344         }
1345 
1346         @Override
1347         @ForceInline
1348         public Class<Short> elementType() {
1349             return short.class;
1350         }
1351 
1352         @Override
1353         @ForceInline
1354         public Class<?> boxType() {
1355             return ShortMaxVector.class;
1356         }
1357 
1358         @Override
1359         @ForceInline
1360         public Class<?> maskType() {
1361             return ShortMaxMask.class;
1362         }
1363 
1364         @Override
1365         @ForceInline
1366         public int elementSize() {
1367             return Short.SIZE;
1368         }
1369 
1370         @Override
1371         @ForceInline
1372         @SuppressWarnings("unchecked")
1373         Class<?> vectorType() {
1374             return ShortMaxVector.class;
1375         }
1376 
1377         @Override
1378         @ForceInline
1379         public Shape shape() {
1380             return Shape.S_Max_BIT;
1381         }
1382 
1383         @Override
1384         ShortMaxVector op(FOp f) {
1385             short[] res = new short[length()];
1386             for (int i = 0; i < length(); i++) {
1387                 res[i] = f.apply(i);
1388             }
1389             return new ShortMaxVector(res);
1390         }
1391 
1392         @Override
1393         ShortMaxVector op(Mask<Short> o, FOp f) {
1394             short[] res = new short[length()];
1395             boolean[] mbits = ((ShortMaxMask)o).getBits();
1396             for (int i = 0; i < length(); i++) {
1397                 if (mbits[i]) {
1398                     res[i] = f.apply(i);
1399                 }
1400             }
1401             return new ShortMaxVector(res);
1402         }
1403 
1404         @Override
1405         ShortMaxMask opm(FOpm f) {
1406             boolean[] res = new boolean[length()];
1407             for (int i = 0; i < length(); i++) {
1408                 res[i] = (boolean)f.apply(i);
1409             }
1410             return new ShortMaxMask(res);
1411         }
1412 
1413         // Factories
1414 
1415         @Override
1416         @ForceInline
1417         public ShortMaxVector zero() {
1418             return VectorIntrinsics.broadcastCoerced(ShortMaxVector.class, short.class, LENGTH,
1419                                                      0, SPECIES,
1420                                                      ((bits, s) -> ((ShortMaxSpecies)s).op(i -> (short)bits)));
1421         }
1422 
1423         @Override
1424         @ForceInline
1425         public ShortMaxVector broadcast(short e) {
1426             return VectorIntrinsics.broadcastCoerced(
1427                 ShortMaxVector.class, short.class, LENGTH,
1428                 e, SPECIES,
1429                 ((bits, s) -> ((ShortMaxSpecies)s).op(i -> (short)bits)));
1430         }
1431 
1432         @Override
1433         @ForceInline
1434         public ShortMaxVector scalars(short... es) {
1435             Objects.requireNonNull(es);
1436             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1437             return VectorIntrinsics.load(ShortMaxVector.class, short.class, LENGTH,
1438                                          es, Unsafe.ARRAY_SHORT_BASE_OFFSET,
1439                                          es, ix, SPECIES,
1440                                          (c, idx, s) -> ((ShortMaxSpecies)s).op(n -> c[idx + n]));
1441         }
1442 
1443         @Override
1444         @ForceInline
1445         public <E> ShortMaxMask cast(Mask<E> m) {
1446             if (m.length() != LENGTH)
1447                 throw new IllegalArgumentException("Mask length this species length differ");
1448             return new ShortMaxMask(m.toArray());
1449         }
1450 
1451         @Override
1452         @ForceInline
1453         public <E> ShortMaxShuffle cast(Shuffle<E> s) {
1454             if (s.length() != LENGTH)
1455                 throw new IllegalArgumentException("Shuffle length this species length differ");
1456             return new ShortMaxShuffle(s.toArray());
1457         }
1458     }
1459 }