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.IntBuffer;
  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 IntMaxVector extends IntVector {
  41     static final IntMaxSpecies SPECIES = new IntMaxSpecies();
  42 
  43     static final IntMaxVector ZERO = new IntMaxVector();
  44 
  45     static final int LENGTH = SPECIES.length();
  46 
  47     // Index vector species
  48     private static final IntVector.IntSpecies INDEX_SPEC;
  49     static {
  50         int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
  51         Vector.Shape shape = Shape.forBitSize(bitSize);
  52         INDEX_SPEC = (IntVector.IntSpecies) Species.of(int.class, shape);
  53     }
  54     private final int[] vec; // Don't access directly, use getElements() instead.
  55 
  56     private int[] getElements() {
  57         return VectorIntrinsics.maybeRebox(this).vec;
  58     }
  59 
  60     IntMaxVector() {
  61         vec = new int[SPECIES.length()];
  62     }
  63 
  64     IntMaxVector(int[] v) {
  65         vec = v;
  66     }
  67 
  68     @Override
  69     public int length() { return LENGTH; }
  70 
  71     // Unary operator
  72 
  73     @Override
  74     IntMaxVector uOp(FUnOp f) {
  75         int[] vec = getElements();
  76         int[] res = new int[length()];
  77         for (int i = 0; i < length(); i++) {
  78             res[i] = f.apply(i, vec[i]);
  79         }
  80         return new IntMaxVector(res);
  81     }
  82 
  83     @Override
  84     IntMaxVector uOp(Mask<Integer> o, FUnOp f) {
  85         int[] vec = getElements();
  86         int[] res = new int[length()];
  87         boolean[] mbits = ((IntMaxMask)o).getBits();
  88         for (int i = 0; i < length(); i++) {
  89             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
  90         }
  91         return new IntMaxVector(res);
  92     }
  93 
  94     // Binary operator
  95 
  96     @Override
  97     IntMaxVector bOp(Vector<Integer> o, FBinOp f) {
  98         int[] res = new int[length()];
  99         int[] vec1 = this.getElements();
 100         int[] vec2 = ((IntMaxVector)o).getElements();
 101         for (int i = 0; i < length(); i++) {
 102             res[i] = f.apply(i, vec1[i], vec2[i]);
 103         }
 104         return new IntMaxVector(res);
 105     }
 106 
 107     @Override
 108     IntMaxVector bOp(Vector<Integer> o1, Mask<Integer> o2, FBinOp f) {
 109         int[] res = new int[length()];
 110         int[] vec1 = this.getElements();
 111         int[] vec2 = ((IntMaxVector)o1).getElements();
 112         boolean[] mbits = ((IntMaxMask)o2).getBits();
 113         for (int i = 0; i < length(); i++) {
 114             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
 115         }
 116         return new IntMaxVector(res);
 117     }
 118 
 119     // Trinary operator
 120 
 121     @Override
 122     IntMaxVector tOp(Vector<Integer> o1, Vector<Integer> o2, FTriOp f) {
 123         int[] res = new int[length()];
 124         int[] vec1 = this.getElements();
 125         int[] vec2 = ((IntMaxVector)o1).getElements();
 126         int[] vec3 = ((IntMaxVector)o2).getElements();
 127         for (int i = 0; i < length(); i++) {
 128             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
 129         }
 130         return new IntMaxVector(res);
 131     }
 132 
 133     @Override
 134     IntMaxVector tOp(Vector<Integer> o1, Vector<Integer> o2, Mask<Integer> o3, FTriOp f) {
 135         int[] res = new int[length()];
 136         int[] vec1 = getElements();
 137         int[] vec2 = ((IntMaxVector)o1).getElements();
 138         int[] vec3 = ((IntMaxVector)o2).getElements();
 139         boolean[] mbits = ((IntMaxMask)o3).getBits();
 140         for (int i = 0; i < length(); i++) {
 141             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
 142         }
 143         return new IntMaxVector(res);
 144     }
 145 
 146     @Override
 147     int rOp(int v, FBinOp f) {
 148         int[] vec = getElements();
 149         for (int i = 0; i < length(); i++) {
 150             v = f.apply(i, v, vec[i]);
 151         }
 152         return v;
 153     }
 154 
 155     @Override
 156     @ForceInline
 157     public <F> Vector<F> cast(Species<F> s) {
 158         Objects.requireNonNull(s);
 159         if (s.length() != LENGTH)
 160             throw new IllegalArgumentException("Vector length this species length differ");
 161 
 162         return VectorIntrinsics.cast(
 163             IntMaxVector.class,
 164             int.class, LENGTH,
 165             s.vectorType(),
 166             s.elementType(), LENGTH,
 167             this, s,
 168             (species, vector) -> vector.castDefault(species)
 169         );
 170     }
 171 
 172     @SuppressWarnings("unchecked")
 173     @ForceInline
 174     private <F> Vector<F> castDefault(Species<F> s) {
 175         int limit = s.length();
 176 
 177         Class<?> stype = s.elementType();
 178         if (stype == byte.class) {
 179             byte[] a = new byte[limit];
 180             for (int i = 0; i < limit; i++) {
 181                 a[i] = (byte) this.get(i);
 182             }
 183             return (Vector) ByteVector.fromArray((ByteVector.ByteSpecies) s, a, 0);
 184         } else if (stype == short.class) {
 185             short[] a = new short[limit];
 186             for (int i = 0; i < limit; i++) {
 187                 a[i] = (short) this.get(i);
 188             }
 189             return (Vector) ShortVector.fromArray((ShortVector.ShortSpecies) s, a, 0);
 190         } else if (stype == int.class) {
 191             int[] a = new int[limit];
 192             for (int i = 0; i < limit; i++) {
 193                 a[i] = (int) this.get(i);
 194             }
 195             return (Vector) IntVector.fromArray((IntVector.IntSpecies) s, a, 0);
 196         } else if (stype == long.class) {
 197             long[] a = new long[limit];
 198             for (int i = 0; i < limit; i++) {
 199                 a[i] = (long) this.get(i);
 200             }
 201             return (Vector) LongVector.fromArray((LongVector.LongSpecies) s, a, 0);
 202         } else if (stype == float.class) {
 203             float[] a = new float[limit];
 204             for (int i = 0; i < limit; i++) {
 205                 a[i] = (float) this.get(i);
 206             }
 207             return (Vector) FloatVector.fromArray((FloatVector.FloatSpecies) s, a, 0);
 208         } else if (stype == double.class) {
 209             double[] a = new double[limit];
 210             for (int i = 0; i < limit; i++) {
 211                 a[i] = (double) this.get(i);
 212             }
 213             return (Vector) DoubleVector.fromArray((DoubleVector.DoubleSpecies) s, a, 0);
 214         } else {
 215             throw new UnsupportedOperationException("Bad lane type for casting.");
 216         }
 217     }
 218 
 219     @Override
 220     @ForceInline
 221     @SuppressWarnings("unchecked")
 222     public <F> Vector<F> reinterpret(Species<F> s) {
 223         Objects.requireNonNull(s);
 224 
 225         if(s.elementType().equals(int.class)) {
 226             return (Vector<F>) reshape((Species<Integer>)s);
 227         }
 228         if(s.bitSize() == bitSize()) {
 229             return reinterpretType(s);
 230         }
 231 
 232         return defaultReinterpret(s);
 233     }
 234 
 235     @ForceInline
 236     private <F> Vector<F> reinterpretType(Species<F> s) {
 237         Objects.requireNonNull(s);
 238 
 239         Class<?> stype = s.elementType();
 240         if (stype == byte.class) {
 241             return VectorIntrinsics.reinterpret(
 242                 IntMaxVector.class,
 243                 int.class, LENGTH,
 244                 ByteMaxVector.class,
 245                 byte.class, ByteMaxVector.LENGTH,
 246                 this, s,
 247                 (species, vector) -> vector.defaultReinterpret(species)
 248             );
 249         } else if (stype == short.class) {
 250             return VectorIntrinsics.reinterpret(
 251                 IntMaxVector.class,
 252                 int.class, LENGTH,
 253                 ShortMaxVector.class,
 254                 short.class, ShortMaxVector.LENGTH,
 255                 this, s,
 256                 (species, vector) -> vector.defaultReinterpret(species)
 257             );
 258         } else if (stype == int.class) {
 259             return VectorIntrinsics.reinterpret(
 260                 IntMaxVector.class,
 261                 int.class, LENGTH,
 262                 IntMaxVector.class,
 263                 int.class, IntMaxVector.LENGTH,
 264                 this, s,
 265                 (species, vector) -> vector.defaultReinterpret(species)
 266             );
 267         } else if (stype == long.class) {
 268             return VectorIntrinsics.reinterpret(
 269                 IntMaxVector.class,
 270                 int.class, LENGTH,
 271                 LongMaxVector.class,
 272                 long.class, LongMaxVector.LENGTH,
 273                 this, s,
 274                 (species, vector) -> vector.defaultReinterpret(species)
 275             );
 276         } else if (stype == float.class) {
 277             return VectorIntrinsics.reinterpret(
 278                 IntMaxVector.class,
 279                 int.class, LENGTH,
 280                 FloatMaxVector.class,
 281                 float.class, FloatMaxVector.LENGTH,
 282                 this, s,
 283                 (species, vector) -> vector.defaultReinterpret(species)
 284             );
 285         } else if (stype == double.class) {
 286             return VectorIntrinsics.reinterpret(
 287                 IntMaxVector.class,
 288                 int.class, LENGTH,
 289                 DoubleMaxVector.class,
 290                 double.class, DoubleMaxVector.LENGTH,
 291                 this, s,
 292                 (species, vector) -> vector.defaultReinterpret(species)
 293             );
 294         } else {
 295             throw new UnsupportedOperationException("Bad lane type for casting.");
 296         }
 297     }
 298 
 299     @Override
 300     @ForceInline
 301     public IntVector reshape(Species<Integer> s) {
 302         Objects.requireNonNull(s);
 303         if (s.bitSize() == 64 && (s instanceof Int64Vector.Int64Species)) {
 304             Int64Vector.Int64Species ts = (Int64Vector.Int64Species)s;
 305             return VectorIntrinsics.reinterpret(
 306                 IntMaxVector.class,
 307                 int.class, LENGTH,
 308                 Int64Vector.class,
 309                 int.class, Int64Vector.LENGTH,
 310                 this, ts,
 311                 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
 312             );
 313         } else if (s.bitSize() == 128 && (s instanceof Int128Vector.Int128Species)) {
 314             Int128Vector.Int128Species ts = (Int128Vector.Int128Species)s;
 315             return VectorIntrinsics.reinterpret(
 316                 IntMaxVector.class,
 317                 int.class, LENGTH,
 318                 Int128Vector.class,
 319                 int.class, Int128Vector.LENGTH,
 320                 this, ts,
 321                 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
 322             );
 323         } else if (s.bitSize() == 256 && (s instanceof Int256Vector.Int256Species)) {
 324             Int256Vector.Int256Species ts = (Int256Vector.Int256Species)s;
 325             return VectorIntrinsics.reinterpret(
 326                 IntMaxVector.class,
 327                 int.class, LENGTH,
 328                 Int256Vector.class,
 329                 int.class, Int256Vector.LENGTH,
 330                 this, ts,
 331                 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
 332             );
 333         } else if (s.bitSize() == 512 && (s instanceof Int512Vector.Int512Species)) {
 334             Int512Vector.Int512Species ts = (Int512Vector.Int512Species)s;
 335             return VectorIntrinsics.reinterpret(
 336                 IntMaxVector.class,
 337                 int.class, LENGTH,
 338                 Int512Vector.class,
 339                 int.class, Int512Vector.LENGTH,
 340                 this, ts,
 341                 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
 342             );
 343         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 344                 && (s.bitSize() % 128 == 0) && (s instanceof IntMaxVector.IntMaxSpecies)) {
 345             IntMaxVector.IntMaxSpecies ts = (IntMaxVector.IntMaxSpecies)s;
 346             return VectorIntrinsics.reinterpret(
 347                 IntMaxVector.class,
 348                 int.class, LENGTH,
 349                 IntMaxVector.class,
 350                 int.class, IntMaxVector.LENGTH,
 351                 this, ts,
 352                 (species, vector) -> (IntVector) vector.defaultReinterpret(species)
 353             );
 354         } else {
 355             throw new InternalError("Unimplemented size");
 356         }
 357     }
 358 
 359     // Binary operations with scalars
 360 
 361     @Override
 362     @ForceInline
 363     public IntVector add(int o) {
 364         return add(SPECIES.broadcast(o));
 365     }
 366 
 367     @Override
 368     @ForceInline
 369     public IntVector add(int o, Mask<Integer> m) {
 370         return add(SPECIES.broadcast(o), m);
 371     }
 372 
 373     @Override
 374     @ForceInline
 375     public IntVector sub(int o) {
 376         return sub(SPECIES.broadcast(o));
 377     }
 378 
 379     @Override
 380     @ForceInline
 381     public IntVector sub(int o, Mask<Integer> m) {
 382         return sub(SPECIES.broadcast(o), m);
 383     }
 384 
 385     @Override
 386     @ForceInline
 387     public IntVector mul(int o) {
 388         return mul(SPECIES.broadcast(o));
 389     }
 390 
 391     @Override
 392     @ForceInline
 393     public IntVector mul(int o, Mask<Integer> m) {
 394         return mul(SPECIES.broadcast(o), m);
 395     }
 396 
 397     @Override
 398     @ForceInline
 399     public IntVector min(int o) {
 400         return min(SPECIES.broadcast(o));
 401     }
 402 
 403     @Override
 404     @ForceInline
 405     public IntVector max(int o) {
 406         return max(SPECIES.broadcast(o));
 407     }
 408 
 409     @Override
 410     @ForceInline
 411     public Mask<Integer> equal(int o) {
 412         return equal(SPECIES.broadcast(o));
 413     }
 414 
 415     @Override
 416     @ForceInline
 417     public Mask<Integer> notEqual(int o) {
 418         return notEqual(SPECIES.broadcast(o));
 419     }
 420 
 421     @Override
 422     @ForceInline
 423     public Mask<Integer> lessThan(int o) {
 424         return lessThan(SPECIES.broadcast(o));
 425     }
 426 
 427     @Override
 428     @ForceInline
 429     public Mask<Integer> lessThanEq(int o) {
 430         return lessThanEq(SPECIES.broadcast(o));
 431     }
 432 
 433     @Override
 434     @ForceInline
 435     public Mask<Integer> greaterThan(int o) {
 436         return greaterThan(SPECIES.broadcast(o));
 437     }
 438 
 439     @Override
 440     @ForceInline
 441     public Mask<Integer> greaterThanEq(int o) {
 442         return greaterThanEq(SPECIES.broadcast(o));
 443     }
 444 
 445     @Override
 446     @ForceInline
 447     public IntVector blend(int o, Mask<Integer> m) {
 448         return blend(SPECIES.broadcast(o), m);
 449     }
 450 
 451 
 452     @Override
 453     @ForceInline
 454     public IntVector and(int o) {
 455         return and(SPECIES.broadcast(o));
 456     }
 457 
 458     @Override
 459     @ForceInline
 460     public IntVector and(int o, Mask<Integer> m) {
 461         return and(SPECIES.broadcast(o), m);
 462     }
 463 
 464     @Override
 465     @ForceInline
 466     public IntVector or(int o) {
 467         return or(SPECIES.broadcast(o));
 468     }
 469 
 470     @Override
 471     @ForceInline
 472     public IntVector or(int o, Mask<Integer> m) {
 473         return or(SPECIES.broadcast(o), m);
 474     }
 475 
 476     @Override
 477     @ForceInline
 478     public IntVector xor(int o) {
 479         return xor(SPECIES.broadcast(o));
 480     }
 481 
 482     @Override
 483     @ForceInline
 484     public IntVector xor(int o, Mask<Integer> m) {
 485         return xor(SPECIES.broadcast(o), m);
 486     }
 487 
 488     @Override
 489     @ForceInline
 490     public IntMaxVector neg() {
 491         return (IntMaxVector)zero(SPECIES).sub(this);
 492     }
 493 
 494     // Unary operations
 495 
 496     @ForceInline
 497     @Override
 498     public IntMaxVector neg(Mask<Integer> m) {
 499         return blend(neg(), m);
 500     }
 501 
 502     @Override
 503     @ForceInline
 504     public IntMaxVector abs() {
 505         return VectorIntrinsics.unaryOp(
 506             VECTOR_OP_ABS, IntMaxVector.class, int.class, LENGTH,
 507             this,
 508             v1 -> v1.uOp((i, a) -> (int) Math.abs(a)));
 509     }
 510 
 511     @ForceInline
 512     @Override
 513     public IntMaxVector abs(Mask<Integer> m) {
 514         return blend(abs(), m);
 515     }
 516 
 517 
 518     @Override
 519     @ForceInline
 520     public IntMaxVector not() {
 521         return VectorIntrinsics.unaryOp(
 522             VECTOR_OP_NOT, IntMaxVector.class, int.class, LENGTH,
 523             this,
 524             v1 -> v1.uOp((i, a) -> (int) ~a));
 525     }
 526 
 527     @ForceInline
 528     @Override
 529     public IntMaxVector not(Mask<Integer> m) {
 530         return blend(not(), m);
 531     }
 532     // Binary operations
 533 
 534     @Override
 535     @ForceInline
 536     public IntMaxVector add(Vector<Integer> o) {
 537         Objects.requireNonNull(o);
 538         IntMaxVector v = (IntMaxVector)o;
 539         return VectorIntrinsics.binaryOp(
 540             VECTOR_OP_ADD, IntMaxVector.class, int.class, LENGTH,
 541             this, v,
 542             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int)(a + b)));
 543     }
 544 
 545     @Override
 546     @ForceInline
 547     public IntMaxVector add(Vector<Integer> v, Mask<Integer> m) {
 548         return blend(add(v), m);
 549     }
 550 
 551     @Override
 552     @ForceInline
 553     public IntMaxVector sub(Vector<Integer> o) {
 554         Objects.requireNonNull(o);
 555         IntMaxVector v = (IntMaxVector)o;
 556         return VectorIntrinsics.binaryOp(
 557             VECTOR_OP_SUB, IntMaxVector.class, int.class, LENGTH,
 558             this, v,
 559             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int)(a - b)));
 560     }
 561 
 562     @Override
 563     @ForceInline
 564     public IntMaxVector sub(Vector<Integer> v, Mask<Integer> m) {
 565         return blend(sub(v), m);
 566     }
 567 
 568     @Override
 569     @ForceInline
 570     public IntMaxVector mul(Vector<Integer> o) {
 571         Objects.requireNonNull(o);
 572         IntMaxVector v = (IntMaxVector)o;
 573         return VectorIntrinsics.binaryOp(
 574             VECTOR_OP_MUL, IntMaxVector.class, int.class, LENGTH,
 575             this, v,
 576             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int)(a * b)));
 577     }
 578 
 579     @Override
 580     @ForceInline
 581     public IntMaxVector mul(Vector<Integer> v, Mask<Integer> m) {
 582         return blend(mul(v), m);
 583     }
 584 
 585     @Override
 586     @ForceInline
 587     public IntMaxVector min(Vector<Integer> o) {
 588         Objects.requireNonNull(o);
 589         IntMaxVector v = (IntMaxVector)o;
 590         return (IntMaxVector) VectorIntrinsics.binaryOp(
 591             VECTOR_OP_MIN, IntMaxVector.class, int.class, LENGTH,
 592             this, v,
 593             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int) Math.min(a, b)));
 594     }
 595 
 596     @Override
 597     @ForceInline
 598     public IntMaxVector min(Vector<Integer> v, Mask<Integer> m) {
 599         return blend(min(v), m);
 600     }
 601 
 602     @Override
 603     @ForceInline
 604     public IntMaxVector max(Vector<Integer> o) {
 605         Objects.requireNonNull(o);
 606         IntMaxVector v = (IntMaxVector)o;
 607         return VectorIntrinsics.binaryOp(
 608             VECTOR_OP_MAX, IntMaxVector.class, int.class, LENGTH,
 609             this, v,
 610             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int) Math.max(a, b)));
 611         }
 612 
 613     @Override
 614     @ForceInline
 615     public IntMaxVector max(Vector<Integer> v, Mask<Integer> m) {
 616         return blend(max(v), m);
 617     }
 618 
 619     @Override
 620     @ForceInline
 621     public IntMaxVector and(Vector<Integer> o) {
 622         Objects.requireNonNull(o);
 623         IntMaxVector v = (IntMaxVector)o;
 624         return VectorIntrinsics.binaryOp(
 625             VECTOR_OP_AND, IntMaxVector.class, int.class, LENGTH,
 626             this, v,
 627             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int)(a & b)));
 628     }
 629 
 630     @Override
 631     @ForceInline
 632     public IntMaxVector or(Vector<Integer> o) {
 633         Objects.requireNonNull(o);
 634         IntMaxVector v = (IntMaxVector)o;
 635         return VectorIntrinsics.binaryOp(
 636             VECTOR_OP_OR, IntMaxVector.class, int.class, LENGTH,
 637             this, v,
 638             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int)(a | b)));
 639     }
 640 
 641     @Override
 642     @ForceInline
 643     public IntMaxVector xor(Vector<Integer> o) {
 644         Objects.requireNonNull(o);
 645         IntMaxVector v = (IntMaxVector)o;
 646         return VectorIntrinsics.binaryOp(
 647             VECTOR_OP_XOR, IntMaxVector.class, int.class, LENGTH,
 648             this, v,
 649             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (int)(a ^ b)));
 650     }
 651 
 652     @Override
 653     @ForceInline
 654     public IntMaxVector and(Vector<Integer> v, Mask<Integer> m) {
 655         return blend(and(v), m);
 656     }
 657 
 658     @Override
 659     @ForceInline
 660     public IntMaxVector or(Vector<Integer> v, Mask<Integer> m) {
 661         return blend(or(v), m);
 662     }
 663 
 664     @Override
 665     @ForceInline
 666     public IntMaxVector xor(Vector<Integer> v, Mask<Integer> m) {
 667         return blend(xor(v), m);
 668     }
 669 
 670     @Override
 671     @ForceInline
 672     public IntMaxVector shiftL(int s) {
 673         return VectorIntrinsics.broadcastInt(
 674             VECTOR_OP_LSHIFT, IntMaxVector.class, int.class, LENGTH,
 675             this, s,
 676             (v, i) -> v.uOp((__, a) -> (int) (a << i)));
 677     }
 678 
 679     @Override
 680     @ForceInline
 681     public IntMaxVector shiftL(int s, Mask<Integer> m) {
 682         return blend(shiftL(s), m);
 683     }
 684 
 685     @Override
 686     @ForceInline
 687     public IntMaxVector shiftR(int s) {
 688         return VectorIntrinsics.broadcastInt(
 689             VECTOR_OP_URSHIFT, IntMaxVector.class, int.class, LENGTH,
 690             this, s,
 691             (v, i) -> v.uOp((__, a) -> (int) (a >>> i)));
 692     }
 693 
 694     @Override
 695     @ForceInline
 696     public IntMaxVector shiftR(int s, Mask<Integer> m) {
 697         return blend(shiftR(s), m);
 698     }
 699 
 700     @Override
 701     @ForceInline
 702     public IntMaxVector aShiftR(int s) {
 703         return VectorIntrinsics.broadcastInt(
 704             VECTOR_OP_RSHIFT, IntMaxVector.class, int.class, LENGTH,
 705             this, s,
 706             (v, i) -> v.uOp((__, a) -> (int) (a >> i)));
 707     }
 708 
 709     @Override
 710     @ForceInline
 711     public IntMaxVector aShiftR(int s, Mask<Integer> m) {
 712         return blend(aShiftR(s), m);
 713     }
 714 
 715     @Override
 716     @ForceInline
 717     public IntMaxVector shiftL(Vector<Integer> s) {
 718         IntMaxVector shiftv = (IntMaxVector)s;
 719         // As per shift specification for Java, mask the shift count.
 720         shiftv = shiftv.and(species().broadcast(0x1f));
 721         return VectorIntrinsics.binaryOp(
 722             VECTOR_OP_LSHIFT, IntMaxVector.class, int.class, LENGTH,
 723             this, shiftv,
 724             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a << b)));
 725     }
 726 
 727     @Override
 728     @ForceInline
 729     public IntMaxVector shiftR(Vector<Integer> s) {
 730         IntMaxVector shiftv = (IntMaxVector)s;
 731         // As per shift specification for Java, mask the shift count.
 732         shiftv = shiftv.and(species().broadcast(0x1f));
 733         return VectorIntrinsics.binaryOp(
 734             VECTOR_OP_URSHIFT, IntMaxVector.class, int.class, LENGTH,
 735             this, shiftv,
 736             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a >>> b)));
 737     }
 738 
 739     @Override
 740     @ForceInline
 741     public IntMaxVector aShiftR(Vector<Integer> s) {
 742         IntMaxVector shiftv = (IntMaxVector)s;
 743         // As per shift specification for Java, mask the shift count.
 744         shiftv = shiftv.and(species().broadcast(0x1f));
 745         return VectorIntrinsics.binaryOp(
 746             VECTOR_OP_RSHIFT, IntMaxVector.class, int.class, LENGTH,
 747             this, shiftv,
 748             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (int) (a >> b)));
 749     }
 750     // Ternary operations
 751 
 752 
 753     // Type specific horizontal reductions
 754 
 755     @Override
 756     @ForceInline
 757     public int addAll() {
 758         return (int) VectorIntrinsics.reductionCoerced(
 759             VECTOR_OP_ADD, IntMaxVector.class, int.class, LENGTH,
 760             this,
 761             v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a + b)));
 762     }
 763 
 764     @Override
 765     @ForceInline
 766     public int andAll() {
 767         return (int) VectorIntrinsics.reductionCoerced(
 768             VECTOR_OP_AND, IntMaxVector.class, int.class, LENGTH,
 769             this,
 770             v -> (long) v.rOp((int) -1, (i, a, b) -> (int) (a & b)));
 771     }
 772 
 773     @Override
 774     @ForceInline
 775     public int andAll(Mask<Integer> m) {
 776         return blend(SPECIES.broadcast((int) -1), m).andAll();
 777     }
 778 
 779     @Override
 780     @ForceInline
 781     public int minAll() {
 782         return (int) VectorIntrinsics.reductionCoerced(
 783             VECTOR_OP_MIN, IntMaxVector.class, int.class, LENGTH,
 784             this,
 785             v -> (long) v.rOp(Integer.MAX_VALUE , (i, a, b) -> (int) Math.min(a, b)));
 786     }
 787 
 788     @Override
 789     @ForceInline
 790     public int maxAll() {
 791         return (int) VectorIntrinsics.reductionCoerced(
 792             VECTOR_OP_MAX, IntMaxVector.class, int.class, LENGTH,
 793             this,
 794             v -> (long) v.rOp(Integer.MIN_VALUE , (i, a, b) -> (int) Math.max(a, b)));
 795     }
 796 
 797     @Override
 798     @ForceInline
 799     public int mulAll() {
 800         return (int) VectorIntrinsics.reductionCoerced(
 801             VECTOR_OP_MUL, IntMaxVector.class, int.class, LENGTH,
 802             this,
 803             v -> (long) v.rOp((int) 1, (i, a, b) -> (int) (a * b)));
 804     }
 805 
 806     @Override
 807     @ForceInline
 808     public int orAll() {
 809         return (int) VectorIntrinsics.reductionCoerced(
 810             VECTOR_OP_OR, IntMaxVector.class, int.class, LENGTH,
 811             this,
 812             v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a | b)));
 813     }
 814 
 815     @Override
 816     @ForceInline
 817     public int orAll(Mask<Integer> m) {
 818         return blend(SPECIES.broadcast((int) 0), m).orAll();
 819     }
 820 
 821     @Override
 822     @ForceInline
 823     public int xorAll() {
 824         return (int) VectorIntrinsics.reductionCoerced(
 825             VECTOR_OP_XOR, IntMaxVector.class, int.class, LENGTH,
 826             this,
 827             v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a ^ b)));
 828     }
 829 
 830     @Override
 831     @ForceInline
 832     public int xorAll(Mask<Integer> m) {
 833         return blend(SPECIES.broadcast((int) 0), m).xorAll();
 834     }
 835 
 836 
 837     @Override
 838     @ForceInline
 839     public int addAll(Mask<Integer> m) {
 840         return blend(SPECIES.broadcast((int) 0), m).addAll();
 841     }
 842 
 843     @Override
 844     @ForceInline
 845     public int mulAll(Mask<Integer> m) {
 846         return blend(SPECIES.broadcast((int) 1), m).mulAll();
 847     }
 848 
 849     @Override
 850     @ForceInline
 851     public int minAll(Mask<Integer> m) {
 852         return blend(SPECIES.broadcast(Integer.MAX_VALUE), m).minAll();
 853     }
 854 
 855     @Override
 856     @ForceInline
 857     public int maxAll(Mask<Integer> m) {
 858         return blend(SPECIES.broadcast(Integer.MIN_VALUE), m).maxAll();
 859     }
 860 
 861     @Override
 862     @ForceInline
 863     public Shuffle<Integer> toShuffle() {
 864         int[] a = toArray();
 865         int[] sa = new int[a.length];
 866         for (int i = 0; i < a.length; i++) {
 867             sa[i] = (int) a[i];
 868         }
 869         return IntVector.shuffleFromArray(SPECIES, sa, 0);
 870     }
 871 
 872     // Memory operations
 873 
 874     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_INT_INDEX_SCALE);
 875     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 876 
 877     @Override
 878     @ForceInline
 879     public void intoArray(int[] a, int ix) {
 880         Objects.requireNonNull(a);
 881         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 882         VectorIntrinsics.store(IntMaxVector.class, int.class, LENGTH,
 883                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
 884                                this,
 885                                a, ix,
 886                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 887     }
 888 
 889     @Override
 890     @ForceInline
 891     public final void intoArray(int[] a, int ax, Mask<Integer> m) {
 892         IntVector oldVal = IntVector.fromArray(SPECIES, a, ax);
 893         IntVector newVal = oldVal.blend(this, m);
 894         newVal.intoArray(a, ax);
 895     }
 896     @Override
 897     @ForceInline
 898     public void intoArray(int[] a, int ix, int[] b, int iy) {
 899         Objects.requireNonNull(a);
 900         Objects.requireNonNull(b);
 901 
 902         // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
 903         IntVector vix = IntVector.fromArray(INDEX_SPEC, b, iy).add(ix);
 904 
 905         vix = VectorIntrinsics.checkIndex(vix, a.length);
 906 
 907         VectorIntrinsics.storeWithMap(IntMaxVector.class, int.class, LENGTH, vix.getClass(),
 908                                a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 909                                this,
 910                                a, ix, b, iy,
 911                                (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
 912     }
 913 
 914      @Override
 915      @ForceInline
 916      public final void intoArray(int[] a, int ax, Mask<Integer> m, int[] b, int iy) {
 917          // @@@ This can result in out of bounds errors for unset mask lanes
 918          IntVector oldVal = IntVector.fromArray(SPECIES, a, ax, b, iy);
 919          IntVector newVal = oldVal.blend(this, m);
 920          newVal.intoArray(a, ax, b, iy);
 921      }
 922 
 923     @Override
 924     @ForceInline
 925     public void intoByteArray(byte[] a, int ix) {
 926         Objects.requireNonNull(a);
 927         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 928         VectorIntrinsics.store(IntMaxVector.class, int.class, LENGTH,
 929                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 930                                this,
 931                                a, ix,
 932                                (c, idx, v) -> {
 933                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 934                                    IntBuffer tb = bbc.asIntBuffer();
 935                                    v.forEach((i, e) -> tb.put(e));
 936                                });
 937     }
 938 
 939     @Override
 940     @ForceInline
 941     public final void intoByteArray(byte[] a, int ix, Mask<Integer> m) {
 942         IntMaxVector oldVal = (IntMaxVector) IntVector.fromByteArray(SPECIES, a, ix);
 943         IntMaxVector newVal = oldVal.blend(this, m);
 944         newVal.intoByteArray(a, ix);
 945     }
 946 
 947     @Override
 948     @ForceInline
 949     public void intoByteBuffer(ByteBuffer bb, int ix) {
 950         if (bb.order() != ByteOrder.nativeOrder()) {
 951             throw new IllegalArgumentException();
 952         }
 953         if (bb.isReadOnly()) {
 954             throw new ReadOnlyBufferException();
 955         }
 956         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 957         VectorIntrinsics.store(IntMaxVector.class, int.class, LENGTH,
 958                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 959                                this,
 960                                bb, ix,
 961                                (c, idx, v) -> {
 962                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 963                                    IntBuffer tb = bbc.asIntBuffer();
 964                                    v.forEach((i, e) -> tb.put(e));
 965                                });
 966     }
 967 
 968     @Override
 969     @ForceInline
 970     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Integer> m) {
 971         IntMaxVector oldVal = (IntMaxVector) IntVector.fromByteBuffer(SPECIES, bb, ix);
 972         IntMaxVector newVal = oldVal.blend(this, m);
 973         newVal.intoByteBuffer(bb, ix);
 974     }
 975 
 976     //
 977 
 978     @Override
 979     public String toString() {
 980         return Arrays.toString(getElements());
 981     }
 982 
 983     @Override
 984     public boolean equals(Object o) {
 985         if (this == o) return true;
 986         if (o == null || this.getClass() != o.getClass()) return false;
 987 
 988         IntMaxVector that = (IntMaxVector) o;
 989         return this.equal(that).allTrue();
 990     }
 991 
 992     @Override
 993     public int hashCode() {
 994         return Arrays.hashCode(vec);
 995     }
 996 
 997     // Binary test
 998 
 999     @Override
1000     IntMaxMask bTest(Vector<Integer> o, FBinTest f) {
1001         int[] vec1 = getElements();
1002         int[] vec2 = ((IntMaxVector)o).getElements();
1003         boolean[] bits = new boolean[length()];
1004         for (int i = 0; i < length(); i++){
1005             bits[i] = f.apply(i, vec1[i], vec2[i]);
1006         }
1007         return new IntMaxMask(bits);
1008     }
1009 
1010     // Comparisons
1011 
1012     @Override
1013     @ForceInline
1014     public IntMaxMask equal(Vector<Integer> o) {
1015         Objects.requireNonNull(o);
1016         IntMaxVector v = (IntMaxVector)o;
1017 
1018         return VectorIntrinsics.compare(
1019             BT_eq, IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1020             this, v,
1021             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1022     }
1023 
1024     @Override
1025     @ForceInline
1026     public IntMaxMask notEqual(Vector<Integer> o) {
1027         Objects.requireNonNull(o);
1028         IntMaxVector v = (IntMaxVector)o;
1029 
1030         return VectorIntrinsics.compare(
1031             BT_ne, IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1032             this, v,
1033             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1034     }
1035 
1036     @Override
1037     @ForceInline
1038     public IntMaxMask lessThan(Vector<Integer> o) {
1039         Objects.requireNonNull(o);
1040         IntMaxVector v = (IntMaxVector)o;
1041 
1042         return VectorIntrinsics.compare(
1043             BT_lt, IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1044             this, v,
1045             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1046     }
1047 
1048     @Override
1049     @ForceInline
1050     public IntMaxMask lessThanEq(Vector<Integer> o) {
1051         Objects.requireNonNull(o);
1052         IntMaxVector v = (IntMaxVector)o;
1053 
1054         return VectorIntrinsics.compare(
1055             BT_le, IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1056             this, v,
1057             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1058     }
1059 
1060     @Override
1061     @ForceInline
1062     public IntMaxMask greaterThan(Vector<Integer> o) {
1063         Objects.requireNonNull(o);
1064         IntMaxVector v = (IntMaxVector)o;
1065 
1066         return (IntMaxMask) VectorIntrinsics.compare(
1067             BT_gt, IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1068             this, v,
1069             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1070     }
1071 
1072     @Override
1073     @ForceInline
1074     public IntMaxMask greaterThanEq(Vector<Integer> o) {
1075         Objects.requireNonNull(o);
1076         IntMaxVector v = (IntMaxVector)o;
1077 
1078         return VectorIntrinsics.compare(
1079             BT_ge, IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1080             this, v,
1081             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1082     }
1083 
1084     // Foreach
1085 
1086     @Override
1087     void forEach(FUnCon f) {
1088         int[] vec = getElements();
1089         for (int i = 0; i < length(); i++) {
1090             f.apply(i, vec[i]);
1091         }
1092     }
1093 
1094     @Override
1095     void forEach(Mask<Integer> o, FUnCon f) {
1096         boolean[] mbits = ((IntMaxMask)o).getBits();
1097         forEach((i, a) -> {
1098             if (mbits[i]) { f.apply(i, a); }
1099         });
1100     }
1101 
1102 
1103     FloatMaxVector toFP() {
1104         int[] vec = getElements();
1105         float[] res = new float[this.species().length()];
1106         for(int i = 0; i < this.species().length(); i++){
1107             res[i] = Float.intBitsToFloat(vec[i]);
1108         }
1109         return new FloatMaxVector(res);
1110     }
1111 
1112     @Override
1113     public IntMaxVector rotateEL(int j) {
1114         int[] vec = getElements();
1115         int[] res = new int[length()];
1116         for (int i = 0; i < length(); i++){
1117             res[(j + i) % length()] = vec[i];
1118         }
1119         return new IntMaxVector(res);
1120     }
1121 
1122     @Override
1123     public IntMaxVector rotateER(int j) {
1124         int[] vec = getElements();
1125         int[] res = new int[length()];
1126         for (int i = 0; i < length(); i++){
1127             int z = i - j;
1128             if(j < 0) {
1129                 res[length() + z] = vec[i];
1130             } else {
1131                 res[z] = vec[i];
1132             }
1133         }
1134         return new IntMaxVector(res);
1135     }
1136 
1137     @Override
1138     public IntMaxVector shiftEL(int j) {
1139         int[] vec = getElements();
1140         int[] res = new int[length()];
1141         for (int i = 0; i < length() - j; i++) {
1142             res[i] = vec[i + j];
1143         }
1144         return new IntMaxVector(res);
1145     }
1146 
1147     @Override
1148     public IntMaxVector shiftER(int j) {
1149         int[] vec = getElements();
1150         int[] res = new int[length()];
1151         for (int i = 0; i < length() - j; i++){
1152             res[i + j] = vec[i];
1153         }
1154         return new IntMaxVector(res);
1155     }
1156 
1157     @Override
1158     @ForceInline
1159     public IntMaxVector rearrange(Vector<Integer> v,
1160                                   Shuffle<Integer> s, Mask<Integer> m) {
1161         return this.rearrange(s).blend(v.rearrange(s), m);
1162     }
1163 
1164     @Override
1165     @ForceInline
1166     public IntMaxVector rearrange(Shuffle<Integer> o1) {
1167         Objects.requireNonNull(o1);
1168         IntMaxShuffle s =  (IntMaxShuffle)o1;
1169 
1170         return VectorIntrinsics.rearrangeOp(
1171             IntMaxVector.class, IntMaxShuffle.class, int.class, LENGTH,
1172             this, s,
1173             (v1, s_) -> v1.uOp((i, a) -> {
1174                 int ei = s_.getElement(i);
1175                 return v1.get(ei);
1176             }));
1177     }
1178 
1179     @Override
1180     @ForceInline
1181     public IntMaxVector blend(Vector<Integer> o1, Mask<Integer> o2) {
1182         Objects.requireNonNull(o1);
1183         Objects.requireNonNull(o2);
1184         IntMaxVector v = (IntMaxVector)o1;
1185         IntMaxMask   m = (IntMaxMask)o2;
1186 
1187         return VectorIntrinsics.blend(
1188             IntMaxVector.class, IntMaxMask.class, int.class, LENGTH,
1189             this, v, m,
1190             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1191     }
1192 
1193     // Accessors
1194 
1195     @Override
1196     public int get(int i) {
1197         if (i < 0 || i >= LENGTH) {
1198             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1199         }
1200         return (int) VectorIntrinsics.extract(
1201                                 IntMaxVector.class, int.class, LENGTH,
1202                                 this, i,
1203                                 (vec, ix) -> {
1204                                     int[] vecarr = vec.getElements();
1205                                     return (long)vecarr[ix];
1206                                 });
1207     }
1208 
1209     @Override
1210     public IntMaxVector with(int i, int e) {
1211         if (i < 0 || i >= LENGTH) {
1212             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1213         }
1214         return VectorIntrinsics.insert(
1215                                 IntMaxVector.class, int.class, LENGTH,
1216                                 this, i, (long)e,
1217                                 (v, ix, bits) -> {
1218                                     int[] res = v.getElements().clone();
1219                                     res[ix] = (int)bits;
1220                                     return new IntMaxVector(res);
1221                                 });
1222     }
1223 
1224     // Mask
1225 
1226     static final class IntMaxMask extends AbstractMask<Integer> {
1227         static final IntMaxMask TRUE_MASK = new IntMaxMask(true);
1228         static final IntMaxMask FALSE_MASK = new IntMaxMask(false);
1229 
1230         private final boolean[] bits; // Don't access directly, use getBits() instead.
1231 
1232         public IntMaxMask(boolean[] bits) {
1233             this(bits, 0);
1234         }
1235 
1236         public IntMaxMask(boolean[] bits, int offset) {
1237             boolean[] a = new boolean[species().length()];
1238             for (int i = 0; i < a.length; i++) {
1239                 a[i] = bits[offset + i];
1240             }
1241             this.bits = a;
1242         }
1243 
1244         public IntMaxMask(boolean val) {
1245             boolean[] bits = new boolean[species().length()];
1246             Arrays.fill(bits, val);
1247             this.bits = bits;
1248         }
1249 
1250         boolean[] getBits() {
1251             return VectorIntrinsics.maybeRebox(this).bits;
1252         }
1253 
1254         @Override
1255         IntMaxMask uOp(MUnOp f) {
1256             boolean[] res = new boolean[species().length()];
1257             boolean[] bits = getBits();
1258             for (int i = 0; i < species().length(); i++) {
1259                 res[i] = f.apply(i, bits[i]);
1260             }
1261             return new IntMaxMask(res);
1262         }
1263 
1264         @Override
1265         IntMaxMask bOp(Mask<Integer> o, MBinOp f) {
1266             boolean[] res = new boolean[species().length()];
1267             boolean[] bits = getBits();
1268             boolean[] mbits = ((IntMaxMask)o).getBits();
1269             for (int i = 0; i < species().length(); i++) {
1270                 res[i] = f.apply(i, bits[i], mbits[i]);
1271             }
1272             return new IntMaxMask(res);
1273         }
1274 
1275         @Override
1276         public IntMaxSpecies species() {
1277             return SPECIES;
1278         }
1279 
1280         @Override
1281         public IntMaxVector toVector() {
1282             int[] res = new int[species().length()];
1283             boolean[] bits = getBits();
1284             for (int i = 0; i < species().length(); i++) {
1285                 // -1 will result in the most significant bit being set in
1286                 // addition to some or all other bits
1287                 res[i] = (int) (bits[i] ? -1 : 0);
1288             }
1289             return new IntMaxVector(res);
1290         }
1291 
1292         // Unary operations
1293 
1294         @Override
1295         @ForceInline
1296         public IntMaxMask not() {
1297             return (IntMaxMask) VectorIntrinsics.unaryOp(
1298                                              VECTOR_OP_NOT, IntMaxMask.class, int.class, LENGTH,
1299                                              this,
1300                                              (m1) -> m1.uOp((i, a) -> !a));
1301         }
1302 
1303         // Binary operations
1304 
1305         @Override
1306         @ForceInline
1307         public IntMaxMask and(Mask<Integer> o) {
1308             Objects.requireNonNull(o);
1309             IntMaxMask m = (IntMaxMask)o;
1310             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, IntMaxMask.class, int.class, LENGTH,
1311                                              this, m,
1312                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1313         }
1314 
1315         @Override
1316         @ForceInline
1317         public IntMaxMask or(Mask<Integer> o) {
1318             Objects.requireNonNull(o);
1319             IntMaxMask m = (IntMaxMask)o;
1320             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, IntMaxMask.class, int.class, LENGTH,
1321                                              this, m,
1322                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1323         }
1324 
1325         // Reductions
1326 
1327         @Override
1328         @ForceInline
1329         public boolean anyTrue() {
1330             return VectorIntrinsics.test(BT_ne, IntMaxMask.class, int.class, LENGTH,
1331                                          this, this,
1332                                          (m, __) -> anyTrueHelper(((IntMaxMask)m).getBits()));
1333         }
1334 
1335         @Override
1336         @ForceInline
1337         public boolean allTrue() {
1338             return VectorIntrinsics.test(BT_overflow, IntMaxMask.class, int.class, LENGTH,
1339                                          this, IntVector.maskAllTrue(species()),
1340                                          (m, __) -> allTrueHelper(((IntMaxMask)m).getBits()));
1341         }
1342     }
1343 
1344     // Shuffle
1345 
1346     static final class IntMaxShuffle extends AbstractShuffle<Integer> {
1347         IntMaxShuffle(byte[] reorder) {
1348             super(reorder);
1349         }
1350 
1351         public IntMaxShuffle(int[] reorder) {
1352             super(reorder);
1353         }
1354 
1355         public IntMaxShuffle(int[] reorder, int i) {
1356             super(reorder, i);
1357         }
1358 
1359         public IntMaxShuffle(IntUnaryOperator f) {
1360             super(f);
1361         }
1362 
1363         @Override
1364         public IntMaxSpecies species() {
1365             return SPECIES;
1366         }
1367 
1368         @Override
1369         public IntVector toVector() {
1370             int[] va = new int[SPECIES.length()];
1371             for (int i = 0; i < va.length; i++) {
1372               va[i] = (int) getElement(i);
1373             }
1374             return IntVector.fromArray(SPECIES, va, 0);
1375         }
1376 
1377         @Override
1378         public IntMaxShuffle rearrange(Vector.Shuffle<Integer> o) {
1379             IntMaxShuffle s = (IntMaxShuffle) o;
1380             byte[] r = new byte[reorder.length];
1381             for (int i = 0; i < reorder.length; i++) {
1382                 r[i] = reorder[s.reorder[i]];
1383             }
1384             return new IntMaxShuffle(r);
1385         }
1386     }
1387 
1388     // Species
1389 
1390     @Override
1391     public IntMaxSpecies species() {
1392         return SPECIES;
1393     }
1394 
1395     static final class IntMaxSpecies extends IntSpecies {
1396         static final int BIT_SIZE = Shape.S_Max_BIT.bitSize();
1397 
1398         static final int LENGTH = BIT_SIZE / Integer.SIZE;
1399 
1400         @Override
1401         public String toString() {
1402            StringBuilder sb = new StringBuilder("Shape[");
1403            sb.append(bitSize()).append(" bits, ");
1404            sb.append(length()).append(" ").append(int.class.getSimpleName()).append("s x ");
1405            sb.append(elementSize()).append(" bits");
1406            sb.append("]");
1407            return sb.toString();
1408         }
1409 
1410         @Override
1411         @ForceInline
1412         public int bitSize() {
1413             return BIT_SIZE;
1414         }
1415 
1416         @Override
1417         @ForceInline
1418         public int length() {
1419             return LENGTH;
1420         }
1421 
1422         @Override
1423         @ForceInline
1424         public Class<Integer> elementType() {
1425             return int.class;
1426         }
1427 
1428         @Override
1429         @ForceInline
1430         public Class<?> boxType() {
1431             return IntMaxVector.class;
1432         }
1433 
1434         @Override
1435         @ForceInline
1436         public Class<?> maskType() {
1437             return IntMaxMask.class;
1438         }
1439 
1440         @Override
1441         @ForceInline
1442         public int elementSize() {
1443             return Integer.SIZE;
1444         }
1445 
1446         @Override
1447         @ForceInline
1448         @SuppressWarnings("unchecked")
1449         Class<?> vectorType() {
1450             return IntMaxVector.class;
1451         }
1452 
1453         @Override
1454         @ForceInline
1455         public Shape shape() {
1456             return Shape.S_Max_BIT;
1457         }
1458 
1459        @Override
1460        IntVector.IntSpecies indexSpecies() {
1461           return INDEX_SPEC;
1462        }
1463 
1464         @Override
1465         IntMaxVector op(FOp f) {
1466             int[] res = new int[length()];
1467             for (int i = 0; i < length(); i++) {
1468                 res[i] = f.apply(i);
1469             }
1470             return new IntMaxVector(res);
1471         }
1472 
1473         @Override
1474         IntMaxVector op(Mask<Integer> o, FOp f) {
1475             int[] res = new int[length()];
1476             boolean[] mbits = ((IntMaxMask)o).getBits();
1477             for (int i = 0; i < length(); i++) {
1478                 if (mbits[i]) {
1479                     res[i] = f.apply(i);
1480                 }
1481             }
1482             return new IntMaxVector(res);
1483         }
1484 
1485         @Override
1486         IntMaxMask opm(FOpm f) {
1487             boolean[] res = new boolean[length()];
1488             for (int i = 0; i < length(); i++) {
1489                 res[i] = (boolean)f.apply(i);
1490             }
1491             return new IntMaxMask(res);
1492         }
1493 
1494         // Factories
1495 
1496         @Override
1497         @ForceInline
1498         public IntMaxVector zero() {
1499             return VectorIntrinsics.broadcastCoerced(IntMaxVector.class, int.class, LENGTH,
1500                                                      0, SPECIES,
1501                                                      ((bits, s) -> ((IntMaxSpecies)s).op(i -> (int)bits)));
1502         }
1503 
1504         @Override
1505         @ForceInline
1506         public IntMaxVector broadcast(int e) {
1507             return VectorIntrinsics.broadcastCoerced(
1508                 IntMaxVector.class, int.class, LENGTH,
1509                 e, SPECIES,
1510                 ((bits, s) -> ((IntMaxSpecies)s).op(i -> (int)bits)));
1511         }
1512 
1513         @Override
1514         @ForceInline
1515         public IntMaxVector scalars(int... es) {
1516             Objects.requireNonNull(es);
1517             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1518             return VectorIntrinsics.load(IntMaxVector.class, int.class, LENGTH,
1519                                          es, Unsafe.ARRAY_INT_BASE_OFFSET,
1520                                          es, ix, SPECIES,
1521                                          (c, idx, s) -> ((IntMaxSpecies)s).op(n -> c[idx + n]));
1522         }
1523 
1524         @Override
1525         @ForceInline
1526         public <E> IntMaxMask cast(Mask<E> m) {
1527             if (m.length() != LENGTH)
1528                 throw new IllegalArgumentException("Mask length this species length differ");
1529             return new IntMaxMask(m.toArray());
1530         }
1531 
1532         @Override
1533         @ForceInline
1534         public <E> IntMaxShuffle cast(Shuffle<E> s) {
1535             if (s.length() != LENGTH)
1536                 throw new IllegalArgumentException("Shuffle length this species length differ");
1537             return new IntMaxShuffle(s.toArray());
1538         }
1539     }
1540 }