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