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 Int256Vector extends IntVector {
  41     static final Int256Species SPECIES = new Int256Species();
  42 
  43     static final Int256Vector ZERO = new Int256Vector();
  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     Int256Vector() {
  61         vec = new int[SPECIES.length()];
  62     }
  63 
  64     Int256Vector(int[] v) {
  65         vec = v;
  66     }
  67 
  68     @Override
  69     public int length() { return LENGTH; }
  70 
  71     // Unary operator
  72 
  73     @Override
  74     Int256Vector 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 Int256Vector(res);
  81     }
  82 
  83     @Override
  84     Int256Vector uOp(Mask<Integer> o, FUnOp f) {
  85         int[] vec = getElements();
  86         int[] res = new int[length()];
  87         boolean[] mbits = ((Int256Mask)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 Int256Vector(res);
  92     }
  93 
  94     // Binary operator
  95 
  96     @Override
  97     Int256Vector bOp(Vector<Integer> o, FBinOp f) {
  98         int[] res = new int[length()];
  99         int[] vec1 = this.getElements();
 100         int[] vec2 = ((Int256Vector)o).getElements();
 101         for (int i = 0; i < length(); i++) {
 102             res[i] = f.apply(i, vec1[i], vec2[i]);
 103         }
 104         return new Int256Vector(res);
 105     }
 106 
 107     @Override
 108     Int256Vector bOp(Vector<Integer> o1, Mask<Integer> o2, FBinOp f) {
 109         int[] res = new int[length()];
 110         int[] vec1 = this.getElements();
 111         int[] vec2 = ((Int256Vector)o1).getElements();
 112         boolean[] mbits = ((Int256Mask)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 Int256Vector(res);
 117     }
 118 
 119     // Trinary operator
 120 
 121     @Override
 122     Int256Vector tOp(Vector<Integer> o1, Vector<Integer> o2, FTriOp f) {
 123         int[] res = new int[length()];
 124         int[] vec1 = this.getElements();
 125         int[] vec2 = ((Int256Vector)o1).getElements();
 126         int[] vec3 = ((Int256Vector)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 Int256Vector(res);
 131     }
 132 
 133     @Override
 134     Int256Vector 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 = ((Int256Vector)o1).getElements();
 138         int[] vec3 = ((Int256Vector)o2).getElements();
 139         boolean[] mbits = ((Int256Mask)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 Int256Vector(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             Int256Vector.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                 Int256Vector.class,
 243                 int.class, LENGTH,
 244                 Byte256Vector.class,
 245                 byte.class, Byte256Vector.LENGTH,
 246                 this, s,
 247                 (species, vector) -> vector.defaultReinterpret(species)
 248             );
 249         } else if (stype == short.class) {
 250             return VectorIntrinsics.reinterpret(
 251                 Int256Vector.class,
 252                 int.class, LENGTH,
 253                 Short256Vector.class,
 254                 short.class, Short256Vector.LENGTH,
 255                 this, s,
 256                 (species, vector) -> vector.defaultReinterpret(species)
 257             );
 258         } else if (stype == int.class) {
 259             return VectorIntrinsics.reinterpret(
 260                 Int256Vector.class,
 261                 int.class, LENGTH,
 262                 Int256Vector.class,
 263                 int.class, Int256Vector.LENGTH,
 264                 this, s,
 265                 (species, vector) -> vector.defaultReinterpret(species)
 266             );
 267         } else if (stype == long.class) {
 268             return VectorIntrinsics.reinterpret(
 269                 Int256Vector.class,
 270                 int.class, LENGTH,
 271                 Long256Vector.class,
 272                 long.class, Long256Vector.LENGTH,
 273                 this, s,
 274                 (species, vector) -> vector.defaultReinterpret(species)
 275             );
 276         } else if (stype == float.class) {
 277             return VectorIntrinsics.reinterpret(
 278                 Int256Vector.class,
 279                 int.class, LENGTH,
 280                 Float256Vector.class,
 281                 float.class, Float256Vector.LENGTH,
 282                 this, s,
 283                 (species, vector) -> vector.defaultReinterpret(species)
 284             );
 285         } else if (stype == double.class) {
 286             return VectorIntrinsics.reinterpret(
 287                 Int256Vector.class,
 288                 int.class, LENGTH,
 289                 Double256Vector.class,
 290                 double.class, Double256Vector.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                 Int256Vector.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                 Int256Vector.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                 Int256Vector.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                 Int256Vector.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                 Int256Vector.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 Int256Vector neg() {
 491         return (Int256Vector)zero(SPECIES).sub(this);
 492     }
 493 
 494     // Unary operations
 495 
 496     @ForceInline
 497     @Override
 498     public Int256Vector neg(Mask<Integer> m) {
 499         return blend(neg(), m);
 500     }
 501 
 502     @Override
 503     @ForceInline
 504     public Int256Vector abs() {
 505         return VectorIntrinsics.unaryOp(
 506             VECTOR_OP_ABS, Int256Vector.class, int.class, LENGTH,
 507             this,
 508             v1 -> v1.uOp((i, a) -> (int) Math.abs(a)));
 509     }
 510 
 511     @ForceInline
 512     @Override
 513     public Int256Vector abs(Mask<Integer> m) {
 514         return blend(abs(), m);
 515     }
 516 
 517 
 518     @Override
 519     @ForceInline
 520     public Int256Vector not() {
 521         return VectorIntrinsics.unaryOp(
 522             VECTOR_OP_NOT, Int256Vector.class, int.class, LENGTH,
 523             this,
 524             v1 -> v1.uOp((i, a) -> (int) ~a));
 525     }
 526 
 527     @ForceInline
 528     @Override
 529     public Int256Vector not(Mask<Integer> m) {
 530         return blend(not(), m);
 531     }
 532     // Binary operations
 533 
 534     @Override
 535     @ForceInline
 536     public Int256Vector add(Vector<Integer> o) {
 537         Objects.requireNonNull(o);
 538         Int256Vector v = (Int256Vector)o;
 539         return VectorIntrinsics.binaryOp(
 540             VECTOR_OP_ADD, Int256Vector.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 Int256Vector add(Vector<Integer> v, Mask<Integer> m) {
 548         return blend(add(v), m);
 549     }
 550 
 551     @Override
 552     @ForceInline
 553     public Int256Vector sub(Vector<Integer> o) {
 554         Objects.requireNonNull(o);
 555         Int256Vector v = (Int256Vector)o;
 556         return VectorIntrinsics.binaryOp(
 557             VECTOR_OP_SUB, Int256Vector.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 Int256Vector sub(Vector<Integer> v, Mask<Integer> m) {
 565         return blend(sub(v), m);
 566     }
 567 
 568     @Override
 569     @ForceInline
 570     public Int256Vector mul(Vector<Integer> o) {
 571         Objects.requireNonNull(o);
 572         Int256Vector v = (Int256Vector)o;
 573         return VectorIntrinsics.binaryOp(
 574             VECTOR_OP_MUL, Int256Vector.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 Int256Vector mul(Vector<Integer> v, Mask<Integer> m) {
 582         return blend(mul(v), m);
 583     }
 584 
 585     @Override
 586     @ForceInline
 587     public Int256Vector min(Vector<Integer> o) {
 588         Objects.requireNonNull(o);
 589         Int256Vector v = (Int256Vector)o;
 590         return (Int256Vector) VectorIntrinsics.binaryOp(
 591             VECTOR_OP_MIN, Int256Vector.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 Int256Vector min(Vector<Integer> v, Mask<Integer> m) {
 599         return blend(min(v), m);
 600     }
 601 
 602     @Override
 603     @ForceInline
 604     public Int256Vector max(Vector<Integer> o) {
 605         Objects.requireNonNull(o);
 606         Int256Vector v = (Int256Vector)o;
 607         return VectorIntrinsics.binaryOp(
 608             VECTOR_OP_MAX, Int256Vector.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 Int256Vector max(Vector<Integer> v, Mask<Integer> m) {
 616         return blend(max(v), m);
 617     }
 618 
 619     @Override
 620     @ForceInline
 621     public Int256Vector and(Vector<Integer> o) {
 622         Objects.requireNonNull(o);
 623         Int256Vector v = (Int256Vector)o;
 624         return VectorIntrinsics.binaryOp(
 625             VECTOR_OP_AND, Int256Vector.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 Int256Vector or(Vector<Integer> o) {
 633         Objects.requireNonNull(o);
 634         Int256Vector v = (Int256Vector)o;
 635         return VectorIntrinsics.binaryOp(
 636             VECTOR_OP_OR, Int256Vector.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 Int256Vector xor(Vector<Integer> o) {
 644         Objects.requireNonNull(o);
 645         Int256Vector v = (Int256Vector)o;
 646         return VectorIntrinsics.binaryOp(
 647             VECTOR_OP_XOR, Int256Vector.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 Int256Vector and(Vector<Integer> v, Mask<Integer> m) {
 655         return blend(and(v), m);
 656     }
 657 
 658     @Override
 659     @ForceInline
 660     public Int256Vector or(Vector<Integer> v, Mask<Integer> m) {
 661         return blend(or(v), m);
 662     }
 663 
 664     @Override
 665     @ForceInline
 666     public Int256Vector xor(Vector<Integer> v, Mask<Integer> m) {
 667         return blend(xor(v), m);
 668     }
 669 
 670     @Override
 671     @ForceInline
 672     public Int256Vector shiftL(int s) {
 673         return VectorIntrinsics.broadcastInt(
 674             VECTOR_OP_LSHIFT, Int256Vector.class, int.class, LENGTH,
 675             this, s,
 676             (v, i) -> v.uOp((__, a) -> (int) (a << i)));
 677     }
 678 
 679     @Override
 680     @ForceInline
 681     public Int256Vector shiftL(int s, Mask<Integer> m) {
 682         return blend(shiftL(s), m);
 683     }
 684 
 685     @Override
 686     @ForceInline
 687     public Int256Vector shiftR(int s) {
 688         return VectorIntrinsics.broadcastInt(
 689             VECTOR_OP_URSHIFT, Int256Vector.class, int.class, LENGTH,
 690             this, s,
 691             (v, i) -> v.uOp((__, a) -> (int) (a >>> i)));
 692     }
 693 
 694     @Override
 695     @ForceInline
 696     public Int256Vector shiftR(int s, Mask<Integer> m) {
 697         return blend(shiftR(s), m);
 698     }
 699 
 700     @Override
 701     @ForceInline
 702     public Int256Vector aShiftR(int s) {
 703         return VectorIntrinsics.broadcastInt(
 704             VECTOR_OP_RSHIFT, Int256Vector.class, int.class, LENGTH,
 705             this, s,
 706             (v, i) -> v.uOp((__, a) -> (int) (a >> i)));
 707     }
 708 
 709     @Override
 710     @ForceInline
 711     public Int256Vector aShiftR(int s, Mask<Integer> m) {
 712         return blend(aShiftR(s), m);
 713     }
 714 
 715     @Override
 716     @ForceInline
 717     public Int256Vector shiftL(Vector<Integer> s) {
 718         Int256Vector shiftv = (Int256Vector)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, Int256Vector.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 Int256Vector shiftR(Vector<Integer> s) {
 730         Int256Vector shiftv = (Int256Vector)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, Int256Vector.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 Int256Vector aShiftR(Vector<Integer> s) {
 742         Int256Vector shiftv = (Int256Vector)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, Int256Vector.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, Int256Vector.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, Int256Vector.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, Int256Vector.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, Int256Vector.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, Int256Vector.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 subAll() {
 809         return (int) VectorIntrinsics.reductionCoerced(
 810             VECTOR_OP_SUB, Int256Vector.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() {
 818         return (int) VectorIntrinsics.reductionCoerced(
 819             VECTOR_OP_OR, Int256Vector.class, int.class, LENGTH,
 820             this,
 821             v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a | b)));
 822     }
 823 
 824     @Override
 825     @ForceInline
 826     public int orAll(Mask<Integer> m) {
 827         return blend(SPECIES.broadcast((int) 0), m).orAll();
 828     }
 829 
 830     @Override
 831     @ForceInline
 832     public int xorAll() {
 833         return (int) VectorIntrinsics.reductionCoerced(
 834             VECTOR_OP_XOR, Int256Vector.class, int.class, LENGTH,
 835             this,
 836             v -> (long) v.rOp((int) 0, (i, a, b) -> (int) (a ^ b)));
 837     }
 838 
 839     @Override
 840     @ForceInline
 841     public int xorAll(Mask<Integer> m) {
 842         return blend(SPECIES.broadcast((int) 0), m).xorAll();
 843     }
 844 
 845 
 846     @Override
 847     @ForceInline
 848     public int addAll(Mask<Integer> m) {
 849         return blend(SPECIES.broadcast((int) 0), m).addAll();
 850     }
 851 
 852     @Override
 853     @ForceInline
 854     public int subAll(Mask<Integer> m) {
 855         return blend(SPECIES.broadcast((int) 0), m).subAll();
 856     }
 857 
 858     @Override
 859     @ForceInline
 860     public int mulAll(Mask<Integer> m) {
 861         return blend(SPECIES.broadcast((int) 1), m).mulAll();
 862     }
 863 
 864     @Override
 865     @ForceInline
 866     public int minAll(Mask<Integer> m) {
 867         return blend(SPECIES.broadcast(Integer.MAX_VALUE), m).minAll();
 868     }
 869 
 870     @Override
 871     @ForceInline
 872     public int maxAll(Mask<Integer> m) {
 873         return blend(SPECIES.broadcast(Integer.MIN_VALUE), m).maxAll();
 874     }
 875 
 876     @Override
 877     @ForceInline
 878     public Shuffle<Integer> toShuffle() {
 879         int[] a = toArray();
 880         int[] sa = new int[a.length];
 881         for (int i = 0; i < a.length; i++) {
 882             sa[i] = (int) a[i];
 883         }
 884         return IntVector.shuffleFromArray(SPECIES, sa, 0);
 885     }
 886 
 887     // Memory operations
 888 
 889     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_INT_INDEX_SCALE);
 890     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 891 
 892     @Override
 893     @ForceInline
 894     public void intoArray(int[] a, int ix) {
 895         Objects.requireNonNull(a);
 896         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 897         VectorIntrinsics.store(Int256Vector.class, int.class, LENGTH,
 898                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
 899                                this,
 900                                a, ix,
 901                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 902     }
 903 
 904     @Override
 905     @ForceInline
 906     public final void intoArray(int[] a, int ax, Mask<Integer> m) {
 907         IntVector oldVal = IntVector.fromArray(SPECIES, a, ax);
 908         IntVector newVal = oldVal.blend(this, m);
 909         newVal.intoArray(a, ax);
 910     }
 911     @Override
 912     @ForceInline
 913     public void intoArray(int[] a, int ix, int[] b, int iy) {
 914         Objects.requireNonNull(a);
 915         Objects.requireNonNull(b);
 916 
 917         // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
 918         IntVector vix = IntVector.fromArray(INDEX_SPEC, b, iy).add(ix);
 919 
 920         vix = VectorIntrinsics.checkIndex(vix, a.length);
 921 
 922         VectorIntrinsics.storeWithMap(Int256Vector.class, int.class, LENGTH, Int256Vector.class,
 923                                a, Unsafe.ARRAY_INT_BASE_OFFSET, vix,
 924                                this,
 925                                a, ix, b, iy,
 926                                (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
 927     }
 928 
 929      @Override
 930      @ForceInline
 931      public final void intoArray(int[] a, int ax, Mask<Integer> m, int[] b, int iy) {
 932          // @@@ This can result in out of bounds errors for unset mask lanes
 933          IntVector oldVal = IntVector.fromArray(SPECIES, a, ax, b, iy);
 934          IntVector newVal = oldVal.blend(this, m);
 935          newVal.intoArray(a, ax, b, iy);
 936      }
 937 
 938     @Override
 939     @ForceInline
 940     public void intoByteArray(byte[] a, int ix) {
 941         Objects.requireNonNull(a);
 942         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
 943         VectorIntrinsics.store(Int256Vector.class, int.class, LENGTH,
 944                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
 945                                this,
 946                                a, ix,
 947                                (c, idx, v) -> {
 948                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
 949                                    IntBuffer tb = bbc.asIntBuffer();
 950                                    v.forEach((i, e) -> tb.put(e));
 951                                });
 952     }
 953 
 954     @Override
 955     @ForceInline
 956     public final void intoByteArray(byte[] a, int ix, Mask<Integer> m) {
 957         Int256Vector oldVal = (Int256Vector) IntVector.fromByteArray(SPECIES, a, ix);
 958         Int256Vector newVal = oldVal.blend(this, m);
 959         newVal.intoByteArray(a, ix);
 960     }
 961 
 962     @Override
 963     @ForceInline
 964     public void intoByteBuffer(ByteBuffer bb, int ix) {
 965         if (bb.order() != ByteOrder.nativeOrder()) {
 966             throw new IllegalArgumentException();
 967         }
 968         if (bb.isReadOnly()) {
 969             throw new ReadOnlyBufferException();
 970         }
 971         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
 972         VectorIntrinsics.store(Int256Vector.class, int.class, LENGTH,
 973                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
 974                                this,
 975                                bb, ix,
 976                                (c, idx, v) -> {
 977                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
 978                                    IntBuffer tb = bbc.asIntBuffer();
 979                                    v.forEach((i, e) -> tb.put(e));
 980                                });
 981     }
 982 
 983     @Override
 984     @ForceInline
 985     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Integer> m) {
 986         Int256Vector oldVal = (Int256Vector) IntVector.fromByteBuffer(SPECIES, bb, ix);
 987         Int256Vector newVal = oldVal.blend(this, m);
 988         newVal.intoByteBuffer(bb, ix);
 989     }
 990 
 991     //
 992 
 993     @Override
 994     public String toString() {
 995         return Arrays.toString(getElements());
 996     }
 997 
 998     @Override
 999     public boolean equals(Object o) {
1000         if (this == o) return true;
1001         if (o == null || this.getClass() != o.getClass()) return false;
1002 
1003         Int256Vector that = (Int256Vector) o;
1004         return this.equal(that).allTrue();
1005     }
1006 
1007     @Override
1008     public int hashCode() {
1009         return Arrays.hashCode(vec);
1010     }
1011 
1012     // Binary test
1013 
1014     @Override
1015     Int256Mask bTest(Vector<Integer> o, FBinTest f) {
1016         int[] vec1 = getElements();
1017         int[] vec2 = ((Int256Vector)o).getElements();
1018         boolean[] bits = new boolean[length()];
1019         for (int i = 0; i < length(); i++){
1020             bits[i] = f.apply(i, vec1[i], vec2[i]);
1021         }
1022         return new Int256Mask(bits);
1023     }
1024 
1025     // Comparisons
1026 
1027     @Override
1028     @ForceInline
1029     public Int256Mask equal(Vector<Integer> o) {
1030         Objects.requireNonNull(o);
1031         Int256Vector v = (Int256Vector)o;
1032 
1033         return VectorIntrinsics.compare(
1034             BT_eq, Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1035             this, v,
1036             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1037     }
1038 
1039     @Override
1040     @ForceInline
1041     public Int256Mask notEqual(Vector<Integer> o) {
1042         Objects.requireNonNull(o);
1043         Int256Vector v = (Int256Vector)o;
1044 
1045         return VectorIntrinsics.compare(
1046             BT_ne, Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1047             this, v,
1048             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1049     }
1050 
1051     @Override
1052     @ForceInline
1053     public Int256Mask lessThan(Vector<Integer> o) {
1054         Objects.requireNonNull(o);
1055         Int256Vector v = (Int256Vector)o;
1056 
1057         return VectorIntrinsics.compare(
1058             BT_lt, Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1059             this, v,
1060             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1061     }
1062 
1063     @Override
1064     @ForceInline
1065     public Int256Mask lessThanEq(Vector<Integer> o) {
1066         Objects.requireNonNull(o);
1067         Int256Vector v = (Int256Vector)o;
1068 
1069         return VectorIntrinsics.compare(
1070             BT_le, Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1071             this, v,
1072             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1073     }
1074 
1075     @Override
1076     @ForceInline
1077     public Int256Mask greaterThan(Vector<Integer> o) {
1078         Objects.requireNonNull(o);
1079         Int256Vector v = (Int256Vector)o;
1080 
1081         return (Int256Mask) VectorIntrinsics.compare(
1082             BT_gt, Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1083             this, v,
1084             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1085     }
1086 
1087     @Override
1088     @ForceInline
1089     public Int256Mask greaterThanEq(Vector<Integer> o) {
1090         Objects.requireNonNull(o);
1091         Int256Vector v = (Int256Vector)o;
1092 
1093         return VectorIntrinsics.compare(
1094             BT_ge, Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1095             this, v,
1096             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1097     }
1098 
1099     // Foreach
1100 
1101     @Override
1102     void forEach(FUnCon f) {
1103         int[] vec = getElements();
1104         for (int i = 0; i < length(); i++) {
1105             f.apply(i, vec[i]);
1106         }
1107     }
1108 
1109     @Override
1110     void forEach(Mask<Integer> o, FUnCon f) {
1111         boolean[] mbits = ((Int256Mask)o).getBits();
1112         forEach((i, a) -> {
1113             if (mbits[i]) { f.apply(i, a); }
1114         });
1115     }
1116 
1117 
1118     Float256Vector toFP() {
1119         int[] vec = getElements();
1120         float[] res = new float[this.species().length()];
1121         for(int i = 0; i < this.species().length(); i++){
1122             res[i] = Float.intBitsToFloat(vec[i]);
1123         }
1124         return new Float256Vector(res);
1125     }
1126 
1127     @Override
1128     public Int256Vector rotateEL(int j) {
1129         int[] vec = getElements();
1130         int[] res = new int[length()];
1131         for (int i = 0; i < length(); i++){
1132             res[(j + i) % length()] = vec[i];
1133         }
1134         return new Int256Vector(res);
1135     }
1136 
1137     @Override
1138     public Int256Vector rotateER(int j) {
1139         int[] vec = getElements();
1140         int[] res = new int[length()];
1141         for (int i = 0; i < length(); i++){
1142             int z = i - j;
1143             if(j < 0) {
1144                 res[length() + z] = vec[i];
1145             } else {
1146                 res[z] = vec[i];
1147             }
1148         }
1149         return new Int256Vector(res);
1150     }
1151 
1152     @Override
1153     public Int256Vector shiftEL(int j) {
1154         int[] vec = getElements();
1155         int[] res = new int[length()];
1156         for (int i = 0; i < length() - j; i++) {
1157             res[i] = vec[i + j];
1158         }
1159         return new Int256Vector(res);
1160     }
1161 
1162     @Override
1163     public Int256Vector shiftER(int j) {
1164         int[] vec = getElements();
1165         int[] res = new int[length()];
1166         for (int i = 0; i < length() - j; i++){
1167             res[i + j] = vec[i];
1168         }
1169         return new Int256Vector(res);
1170     }
1171 
1172     @Override
1173     @ForceInline
1174     public Int256Vector rearrange(Vector<Integer> v,
1175                                   Shuffle<Integer> s, Mask<Integer> m) {
1176         return this.rearrange(s).blend(v.rearrange(s), m);
1177     }
1178 
1179     @Override
1180     @ForceInline
1181     public Int256Vector rearrange(Shuffle<Integer> o1) {
1182         Objects.requireNonNull(o1);
1183         Int256Shuffle s =  (Int256Shuffle)o1;
1184 
1185         return VectorIntrinsics.rearrangeOp(
1186             Int256Vector.class, Int256Shuffle.class, int.class, LENGTH,
1187             this, s,
1188             (v1, s_) -> v1.uOp((i, a) -> {
1189                 int ei = s_.getElement(i);
1190                 return v1.get(ei);
1191             }));
1192     }
1193 
1194     @Override
1195     @ForceInline
1196     public Int256Vector blend(Vector<Integer> o1, Mask<Integer> o2) {
1197         Objects.requireNonNull(o1);
1198         Objects.requireNonNull(o2);
1199         Int256Vector v = (Int256Vector)o1;
1200         Int256Mask   m = (Int256Mask)o2;
1201 
1202         return VectorIntrinsics.blend(
1203             Int256Vector.class, Int256Mask.class, int.class, LENGTH,
1204             this, v, m,
1205             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1206     }
1207 
1208     // Accessors
1209 
1210     @Override
1211     public int get(int i) {
1212         if (i < 0 || i >= LENGTH) {
1213             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1214         }
1215         return (int) VectorIntrinsics.extract(
1216                                 Int256Vector.class, int.class, LENGTH,
1217                                 this, i,
1218                                 (vec, ix) -> {
1219                                     int[] vecarr = vec.getElements();
1220                                     return (long)vecarr[ix];
1221                                 });
1222     }
1223 
1224     @Override
1225     public Int256Vector with(int i, int e) {
1226         if (i < 0 || i >= LENGTH) {
1227             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1228         }
1229         return VectorIntrinsics.insert(
1230                                 Int256Vector.class, int.class, LENGTH,
1231                                 this, i, (long)e,
1232                                 (v, ix, bits) -> {
1233                                     int[] res = v.getElements().clone();
1234                                     res[ix] = (int)bits;
1235                                     return new Int256Vector(res);
1236                                 });
1237     }
1238 
1239     // Mask
1240 
1241     static final class Int256Mask extends AbstractMask<Integer> {
1242         static final Int256Mask TRUE_MASK = new Int256Mask(true);
1243         static final Int256Mask FALSE_MASK = new Int256Mask(false);
1244 
1245         private final boolean[] bits; // Don't access directly, use getBits() instead.
1246 
1247         public Int256Mask(boolean[] bits) {
1248             this(bits, 0);
1249         }
1250 
1251         public Int256Mask(boolean[] bits, int offset) {
1252             boolean[] a = new boolean[species().length()];
1253             for (int i = 0; i < a.length; i++) {
1254                 a[i] = bits[offset + i];
1255             }
1256             this.bits = a;
1257         }
1258 
1259         public Int256Mask(boolean val) {
1260             boolean[] bits = new boolean[species().length()];
1261             Arrays.fill(bits, val);
1262             this.bits = bits;
1263         }
1264 
1265         boolean[] getBits() {
1266             return VectorIntrinsics.maybeRebox(this).bits;
1267         }
1268 
1269         @Override
1270         Int256Mask uOp(MUnOp f) {
1271             boolean[] res = new boolean[species().length()];
1272             boolean[] bits = getBits();
1273             for (int i = 0; i < species().length(); i++) {
1274                 res[i] = f.apply(i, bits[i]);
1275             }
1276             return new Int256Mask(res);
1277         }
1278 
1279         @Override
1280         Int256Mask bOp(Mask<Integer> o, MBinOp f) {
1281             boolean[] res = new boolean[species().length()];
1282             boolean[] bits = getBits();
1283             boolean[] mbits = ((Int256Mask)o).getBits();
1284             for (int i = 0; i < species().length(); i++) {
1285                 res[i] = f.apply(i, bits[i], mbits[i]);
1286             }
1287             return new Int256Mask(res);
1288         }
1289 
1290         @Override
1291         public Int256Species species() {
1292             return SPECIES;
1293         }
1294 
1295         @Override
1296         public Int256Vector toVector() {
1297             int[] res = new int[species().length()];
1298             boolean[] bits = getBits();
1299             for (int i = 0; i < species().length(); i++) {
1300                 // -1 will result in the most significant bit being set in
1301                 // addition to some or all other bits
1302                 res[i] = (int) (bits[i] ? -1 : 0);
1303             }
1304             return new Int256Vector(res);
1305         }
1306 
1307         // Unary operations
1308 
1309         @Override
1310         @ForceInline
1311         public Int256Mask not() {
1312             return (Int256Mask) VectorIntrinsics.unaryOp(
1313                                              VECTOR_OP_NOT, Int256Mask.class, int.class, LENGTH,
1314                                              this,
1315                                              (m1) -> m1.uOp((i, a) -> !a));
1316         }
1317 
1318         // Binary operations
1319 
1320         @Override
1321         @ForceInline
1322         public Int256Mask and(Mask<Integer> o) {
1323             Objects.requireNonNull(o);
1324             Int256Mask m = (Int256Mask)o;
1325             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Int256Mask.class, int.class, LENGTH,
1326                                              this, m,
1327                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1328         }
1329 
1330         @Override
1331         @ForceInline
1332         public Int256Mask or(Mask<Integer> o) {
1333             Objects.requireNonNull(o);
1334             Int256Mask m = (Int256Mask)o;
1335             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Int256Mask.class, int.class, LENGTH,
1336                                              this, m,
1337                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1338         }
1339 
1340         // Reductions
1341 
1342         @Override
1343         @ForceInline
1344         public boolean anyTrue() {
1345             return VectorIntrinsics.test(BT_ne, Int256Mask.class, int.class, LENGTH,
1346                                          this, this,
1347                                          (m, __) -> anyTrueHelper(((Int256Mask)m).getBits()));
1348         }
1349 
1350         @Override
1351         @ForceInline
1352         public boolean allTrue() {
1353             return VectorIntrinsics.test(BT_overflow, Int256Mask.class, int.class, LENGTH,
1354                                          this, IntVector.maskAllTrue(species()),
1355                                          (m, __) -> allTrueHelper(((Int256Mask)m).getBits()));
1356         }
1357     }
1358 
1359     // Shuffle
1360 
1361     static final class Int256Shuffle extends AbstractShuffle<Integer> {
1362         Int256Shuffle(byte[] reorder) {
1363             super(reorder);
1364         }
1365 
1366         public Int256Shuffle(int[] reorder) {
1367             super(reorder);
1368         }
1369 
1370         public Int256Shuffle(int[] reorder, int i) {
1371             super(reorder, i);
1372         }
1373 
1374         public Int256Shuffle(IntUnaryOperator f) {
1375             super(f);
1376         }
1377 
1378         @Override
1379         public Int256Species species() {
1380             return SPECIES;
1381         }
1382 
1383         @Override
1384         public IntVector toVector() {
1385             int[] va = new int[SPECIES.length()];
1386             for (int i = 0; i < va.length; i++) {
1387               va[i] = (int) getElement(i);
1388             }
1389             return IntVector.fromArray(SPECIES, va, 0);
1390         }
1391 
1392         @Override
1393         public Int256Shuffle rearrange(Vector.Shuffle<Integer> o) {
1394             Int256Shuffle s = (Int256Shuffle) o;
1395             byte[] r = new byte[reorder.length];
1396             for (int i = 0; i < reorder.length; i++) {
1397                 r[i] = reorder[s.reorder[i]];
1398             }
1399             return new Int256Shuffle(r);
1400         }
1401     }
1402 
1403     // Species
1404 
1405     @Override
1406     public Int256Species species() {
1407         return SPECIES;
1408     }
1409 
1410     static final class Int256Species extends IntSpecies {
1411         static final int BIT_SIZE = Shape.S_256_BIT.bitSize();
1412 
1413         static final int LENGTH = BIT_SIZE / Integer.SIZE;
1414 
1415         @Override
1416         public String toString() {
1417            StringBuilder sb = new StringBuilder("Shape[");
1418            sb.append(bitSize()).append(" bits, ");
1419            sb.append(length()).append(" ").append(int.class.getSimpleName()).append("s x ");
1420            sb.append(elementSize()).append(" bits");
1421            sb.append("]");
1422            return sb.toString();
1423         }
1424 
1425         @Override
1426         @ForceInline
1427         public int bitSize() {
1428             return BIT_SIZE;
1429         }
1430 
1431         @Override
1432         @ForceInline
1433         public int length() {
1434             return LENGTH;
1435         }
1436 
1437         @Override
1438         @ForceInline
1439         public Class<Integer> elementType() {
1440             return int.class;
1441         }
1442 
1443         @Override
1444         @ForceInline
1445         public Class<?> boxType() {
1446             return Int256Vector.class;
1447         }
1448 
1449         @Override
1450         @ForceInline
1451         public Class<?> maskType() {
1452             return Int256Mask.class;
1453         }
1454 
1455         @Override
1456         @ForceInline
1457         public int elementSize() {
1458             return Integer.SIZE;
1459         }
1460 
1461         @Override
1462         @ForceInline
1463         @SuppressWarnings("unchecked")
1464         Class<?> vectorType() {
1465             return Int256Vector.class;
1466         }
1467 
1468         @Override
1469         @ForceInline
1470         public Shape shape() {
1471             return Shape.S_256_BIT;
1472         }
1473 
1474        @Override
1475        IntVector.IntSpecies indexSpecies() {
1476           return INDEX_SPEC;
1477        }
1478 
1479         @Override
1480         Int256Vector op(FOp f) {
1481             int[] res = new int[length()];
1482             for (int i = 0; i < length(); i++) {
1483                 res[i] = f.apply(i);
1484             }
1485             return new Int256Vector(res);
1486         }
1487 
1488         @Override
1489         Int256Vector op(Mask<Integer> o, FOp f) {
1490             int[] res = new int[length()];
1491             boolean[] mbits = ((Int256Mask)o).getBits();
1492             for (int i = 0; i < length(); i++) {
1493                 if (mbits[i]) {
1494                     res[i] = f.apply(i);
1495                 }
1496             }
1497             return new Int256Vector(res);
1498         }
1499 
1500         @Override
1501         Int256Mask opm(FOpm f) {
1502             boolean[] res = new boolean[length()];
1503             for (int i = 0; i < length(); i++) {
1504                 res[i] = (boolean)f.apply(i);
1505             }
1506             return new Int256Mask(res);
1507         }
1508 
1509         // Factories
1510 
1511         @Override
1512         @ForceInline
1513         public Int256Vector zero() {
1514             return VectorIntrinsics.broadcastCoerced(Int256Vector.class, int.class, LENGTH,
1515                                                      0, SPECIES,
1516                                                      ((bits, s) -> ((Int256Species)s).op(i -> (int)bits)));
1517         }
1518 
1519         @Override
1520         @ForceInline
1521         public Int256Vector broadcast(int e) {
1522             return VectorIntrinsics.broadcastCoerced(
1523                 Int256Vector.class, int.class, LENGTH,
1524                 e, SPECIES,
1525                 ((bits, s) -> ((Int256Species)s).op(i -> (int)bits)));
1526         }
1527 
1528         @Override
1529         @ForceInline
1530         public Int256Vector scalars(int... es) {
1531             Objects.requireNonNull(es);
1532             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1533             return VectorIntrinsics.load(Int256Vector.class, int.class, LENGTH,
1534                                          es, Unsafe.ARRAY_INT_BASE_OFFSET,
1535                                          es, ix, SPECIES,
1536                                          (c, idx, s) -> ((Int256Species)s).op(n -> c[idx + n]));
1537         }
1538 
1539         @Override
1540         @ForceInline
1541         public <E> Int256Mask cast(Mask<E> m) {
1542             if (m.length() != LENGTH)
1543                 throw new IllegalArgumentException("Mask length this species length differ");
1544             return new Int256Mask(m.toArray());
1545         }
1546 
1547         @Override
1548         @ForceInline
1549         public <E> Int256Shuffle cast(Shuffle<E> s) {
1550             if (s.length() != LENGTH)
1551                 throw new IllegalArgumentException("Shuffle length this species length differ");
1552             return new Int256Shuffle(s.toArray());
1553         }
1554     }
1555 }