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 Int512Vector extends IntVector<Shapes.S512Bit> {
  41     static final Int512Species SPECIES = new Int512Species();
  42 
  43     static final Int512Vector ZERO = new Int512Vector();
  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     Int512Vector() {
  54         vec = new int[SPECIES.length()];
  55     }
  56 
  57     Int512Vector(int[] v) {
  58         vec = v;
  59     }
  60 
  61     @Override
  62     public int length() { return LENGTH; }
  63 
  64     // Unary operator
  65 
  66     @Override
  67     Int512Vector 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 Int512Vector(res);
  74     }
  75 
  76     @Override
  77     Int512Vector uOp(Mask<Integer, Shapes.S512Bit> o, FUnOp f) {
  78         int[] vec = getElements();
  79         int[] res = new int[length()];
  80         boolean[] mbits = ((Int512Mask)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 Int512Vector(res);
  85     }
  86 
  87     // Binary operator
  88 
  89     @Override
  90     Int512Vector bOp(Vector<Integer, Shapes.S512Bit> o, FBinOp f) {
  91         int[] res = new int[length()];
  92         int[] vec1 = this.getElements();
  93         int[] vec2 = ((Int512Vector)o).getElements();
  94         for (int i = 0; i < length(); i++) {
  95             res[i] = f.apply(i, vec1[i], vec2[i]);
  96         }
  97         return new Int512Vector(res);
  98     }
  99 
 100     @Override
 101     Int512Vector bOp(Vector<Integer, Shapes.S512Bit> o1, Mask<Integer, Shapes.S512Bit> o2, FBinOp f) {
 102         int[] res = new int[length()];
 103         int[] vec1 = this.getElements();
 104         int[] vec2 = ((Int512Vector)o1).getElements();
 105         boolean[] mbits = ((Int512Mask)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 Int512Vector(res);
 110     }
 111 
 112     // Trinary operator
 113 
 114     @Override
 115     Int512Vector tOp(Vector<Integer, Shapes.S512Bit> o1, Vector<Integer, Shapes.S512Bit> o2, FTriOp f) {
 116         int[] res = new int[length()];
 117         int[] vec1 = this.getElements();
 118         int[] vec2 = ((Int512Vector)o1).getElements();
 119         int[] vec3 = ((Int512Vector)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 Int512Vector(res);
 124     }
 125 
 126     @Override
 127     Int512Vector tOp(Vector<Integer, Shapes.S512Bit> o1, Vector<Integer, Shapes.S512Bit> o2, Mask<Integer, Shapes.S512Bit> o3, FTriOp f) {
 128         int[] res = new int[length()];
 129         int[] vec1 = getElements();
 130         int[] vec2 = ((Int512Vector)o1).getElements();
 131         int[] vec3 = ((Int512Vector)o2).getElements();
 132         boolean[] mbits = ((Int512Mask)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 Int512Vector(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.S512Bit> add(int o) {
 153         return add(SPECIES.broadcast(o));
 154     }
 155 
 156     @Override
 157     @ForceInline
 158     public IntVector<Shapes.S512Bit> add(int o, Mask<Integer,Shapes.S512Bit> m) {
 159         return add(SPECIES.broadcast(o), m);
 160     }
 161 
 162     @Override
 163     @ForceInline
 164     public IntVector<Shapes.S512Bit> sub(int o) {
 165         return sub(SPECIES.broadcast(o));
 166     }
 167 
 168     @Override
 169     @ForceInline
 170     public IntVector<Shapes.S512Bit> sub(int o, Mask<Integer,Shapes.S512Bit> m) {
 171         return sub(SPECIES.broadcast(o), m);
 172     }
 173 
 174     @Override
 175     @ForceInline
 176     public IntVector<Shapes.S512Bit> mul(int o) {
 177         return mul(SPECIES.broadcast(o));
 178     }
 179 
 180     @Override
 181     @ForceInline
 182     public IntVector<Shapes.S512Bit> mul(int o, Mask<Integer,Shapes.S512Bit> m) {
 183         return mul(SPECIES.broadcast(o), m);
 184     }
 185 
 186     @Override
 187     @ForceInline
 188     public IntVector<Shapes.S512Bit> min(int o) {
 189         return min(SPECIES.broadcast(o));
 190     }
 191 
 192     @Override
 193     @ForceInline
 194     public IntVector<Shapes.S512Bit> max(int o) {
 195         return max(SPECIES.broadcast(o));
 196     }
 197 
 198     @Override
 199     @ForceInline
 200     public Mask<Integer, Shapes.S512Bit> equal(int o) {
 201         return equal(SPECIES.broadcast(o));
 202     }
 203 
 204     @Override
 205     @ForceInline
 206     public Mask<Integer, Shapes.S512Bit> notEqual(int o) {
 207         return notEqual(SPECIES.broadcast(o));
 208     }
 209 
 210     @Override
 211     @ForceInline
 212     public Mask<Integer, Shapes.S512Bit> lessThan(int o) {
 213         return lessThan(SPECIES.broadcast(o));
 214     }
 215 
 216     @Override
 217     @ForceInline
 218     public Mask<Integer, Shapes.S512Bit> lessThanEq(int o) {
 219         return lessThanEq(SPECIES.broadcast(o));
 220     }
 221 
 222     @Override
 223     @ForceInline
 224     public Mask<Integer, Shapes.S512Bit> greaterThan(int o) {
 225         return greaterThan(SPECIES.broadcast(o));
 226     }
 227 
 228     @Override
 229     @ForceInline
 230     public Mask<Integer, Shapes.S512Bit> greaterThanEq(int o) {
 231         return greaterThanEq(SPECIES.broadcast(o));
 232     }
 233 
 234     @Override
 235     @ForceInline
 236     public IntVector<Shapes.S512Bit> blend(int o, Mask<Integer,Shapes.S512Bit> m) {
 237         return blend(SPECIES.broadcast(o), m);
 238     }
 239 
 240 
 241     @Override
 242     @ForceInline
 243     public IntVector<Shapes.S512Bit> and(int o) {
 244         return and(SPECIES.broadcast(o));
 245     }
 246 
 247     @Override
 248     @ForceInline
 249     public IntVector<Shapes.S512Bit> and(int o, Mask<Integer,Shapes.S512Bit> m) {
 250         return and(SPECIES.broadcast(o), m);
 251     }
 252 
 253     @Override
 254     @ForceInline
 255     public IntVector<Shapes.S512Bit> or(int o) {
 256         return or(SPECIES.broadcast(o));
 257     }
 258 
 259     @Override
 260     @ForceInline
 261     public IntVector<Shapes.S512Bit> or(int o, Mask<Integer,Shapes.S512Bit> m) {
 262         return or(SPECIES.broadcast(o), m);
 263     }
 264 
 265     @Override
 266     @ForceInline
 267     public IntVector<Shapes.S512Bit> xor(int o) {
 268         return xor(SPECIES.broadcast(o));
 269     }
 270 
 271     @Override
 272     @ForceInline
 273     public IntVector<Shapes.S512Bit> xor(int o, Mask<Integer,Shapes.S512Bit> m) {
 274         return xor(SPECIES.broadcast(o), m);
 275     }
 276 
 277     @Override
 278     @ForceInline
 279     public Int512Vector neg() {
 280         return SPECIES.zero().sub(this);
 281     }
 282 
 283     // Unary operations
 284 
 285     @ForceInline
 286     @Override
 287     public Int512Vector neg(Mask<Integer, Shapes.S512Bit> m) {
 288         return blend(neg(), m);
 289     }
 290 
 291     @Override
 292     @ForceInline
 293     public Int512Vector abs() {
 294         return VectorIntrinsics.unaryOp(
 295             VECTOR_OP_ABS, Int512Vector.class, int.class, LENGTH,
 296             this,
 297             v1 -> v1.uOp((i, a) -> (int) Math.abs(a)));
 298     }
 299 
 300     @ForceInline
 301     @Override
 302     public Int512Vector abs(Mask<Integer, Shapes.S512Bit> m) {
 303         return blend(abs(), m);
 304     }
 305 
 306 
 307     @Override
 308     @ForceInline
 309     public Int512Vector not() {
 310         return VectorIntrinsics.unaryOp(
 311             VECTOR_OP_NOT, Int512Vector.class, int.class, LENGTH,
 312             this,
 313             v1 -> v1.uOp((i, a) -> (int) ~a));
 314     }
 315 
 316     @ForceInline
 317     @Override
 318     public Int512Vector not(Mask<Integer, Shapes.S512Bit> m) {
 319         return blend(not(), m);
 320     }
 321     // Binary operations
 322 
 323     @Override
 324     @ForceInline
 325     public Int512Vector add(Vector<Integer,Shapes.S512Bit> o) {
 326         Objects.requireNonNull(o);
 327         Int512Vector v = (Int512Vector)o;
 328         return VectorIntrinsics.binaryOp(
 329             VECTOR_OP_ADD, Int512Vector.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 Int512Vector add(Vector<Integer,Shapes.S512Bit> v, Mask<Integer, Shapes.S512Bit> m) {
 337         return blend(add(v), m);
 338     }
 339 
 340     @Override
 341     @ForceInline
 342     public Int512Vector sub(Vector<Integer,Shapes.S512Bit> o) {
 343         Objects.requireNonNull(o);
 344         Int512Vector v = (Int512Vector)o;
 345         return VectorIntrinsics.binaryOp(
 346             VECTOR_OP_SUB, Int512Vector.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 Int512Vector sub(Vector<Integer,Shapes.S512Bit> v, Mask<Integer, Shapes.S512Bit> m) {
 354         return blend(sub(v), m);
 355     }
 356 
 357     @Override
 358     @ForceInline
 359     public Int512Vector mul(Vector<Integer,Shapes.S512Bit> o) {
 360         Objects.requireNonNull(o);
 361         Int512Vector v = (Int512Vector)o;
 362         return VectorIntrinsics.binaryOp(
 363             VECTOR_OP_MUL, Int512Vector.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 Int512Vector mul(Vector<Integer,Shapes.S512Bit> v, Mask<Integer, Shapes.S512Bit> m) {
 371         return blend(mul(v), m);
 372     }
 373 
 374     @Override
 375     @ForceInline
 376     public Int512Vector min(Vector<Integer,Shapes.S512Bit> o) {
 377         Objects.requireNonNull(o);
 378         Int512Vector v = (Int512Vector)o;
 379         return (Int512Vector) VectorIntrinsics.binaryOp(
 380             VECTOR_OP_MIN, Int512Vector.class, int.class, LENGTH,
 381             this, v,
 382             (v1, v2) -> ((Int512Vector)v1).bOp(v2, (i, a, b) -> (int) ((a < b) ? a : b)));
 383     }
 384 
 385     @Override
 386     @ForceInline
 387     public Int512Vector max(Vector<Integer,Shapes.S512Bit> o) {
 388         Objects.requireNonNull(o);
 389         Int512Vector v = (Int512Vector)o;
 390         return VectorIntrinsics.binaryOp(
 391             VECTOR_OP_MAX, Int512Vector.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 Int512Vector and(Vector<Integer,Shapes.S512Bit> o) {
 399         Objects.requireNonNull(o);
 400         Int512Vector v = (Int512Vector)o;
 401         return VectorIntrinsics.binaryOp(
 402             VECTOR_OP_AND, Int512Vector.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 Int512Vector or(Vector<Integer,Shapes.S512Bit> o) {
 410         Objects.requireNonNull(o);
 411         Int512Vector v = (Int512Vector)o;
 412         return VectorIntrinsics.binaryOp(
 413             VECTOR_OP_OR, Int512Vector.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 Int512Vector xor(Vector<Integer,Shapes.S512Bit> o) {
 421         Objects.requireNonNull(o);
 422         Int512Vector v = (Int512Vector)o;
 423         return VectorIntrinsics.binaryOp(
 424             VECTOR_OP_XOR, Int512Vector.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 Int512Vector and(Vector<Integer,Shapes.S512Bit> v, Mask<Integer, Shapes.S512Bit> m) {
 432         return blend(and(v), m);
 433     }
 434 
 435     @Override
 436     @ForceInline
 437     public Int512Vector or(Vector<Integer,Shapes.S512Bit> v, Mask<Integer, Shapes.S512Bit> m) {
 438         return blend(or(v), m);
 439     }
 440 
 441     @Override
 442     @ForceInline
 443     public Int512Vector xor(Vector<Integer,Shapes.S512Bit> v, Mask<Integer, Shapes.S512Bit> m) {
 444         return blend(xor(v), m);
 445     }
 446 
 447     @Override
 448     @ForceInline
 449     public Int512Vector shiftL(int s) {
 450         return VectorIntrinsics.broadcastInt(
 451             VECTOR_OP_LSHIFT, Int512Vector.class, int.class, LENGTH,
 452             this, s,
 453             (v, i) -> v.uOp((__, a) -> (int) (a << i)));
 454     }
 455 
 456     @Override
 457     @ForceInline
 458     public Int512Vector shiftR(int s) {
 459         return VectorIntrinsics.broadcastInt(
 460             VECTOR_OP_URSHIFT, Int512Vector.class, int.class, LENGTH,
 461             this, s,
 462             (v, i) -> v.uOp((__, a) -> (int) (a >>> i)));
 463     }
 464 
 465     @Override
 466     @ForceInline
 467     public Int512Vector aShiftR(int s) {
 468         return VectorIntrinsics.broadcastInt(
 469             VECTOR_OP_RSHIFT, Int512Vector.class, int.class, LENGTH,
 470             this, s,
 471             (v, i) -> v.uOp((__, a) -> (int) (a >> i)));
 472     }
 473 
 474     @Override
 475     @ForceInline
 476     public Int512Vector shiftL(Vector<Integer,Shapes.S512Bit> s) {
 477         Int512Vector shiftv = (Int512Vector)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, Int512Vector.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 Int512Vector shiftR(Vector<Integer,Shapes.S512Bit> s) {
 489         Int512Vector shiftv = (Int512Vector)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, Int512Vector.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 Int512Vector aShiftR(Vector<Integer,Shapes.S512Bit> s) {
 501         Int512Vector shiftv = (Int512Vector)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, Int512Vector.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, Int512Vector.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, Int512Vector.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.S512Bit> 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, Int512Vector.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, Int512Vector.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, Int512Vector.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, Int512Vector.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, Int512Vector.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.S512Bit> 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, Int512Vector.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.S512Bit> m) {
 601         return blend(SPECIES.broadcast((int) 0), m).xorAll();
 602     }
 603 
 604 
 605     @Override
 606     @ForceInline
 607     public int addAll(Mask<Integer, Shapes.S512Bit> m) {
 608         return blend(SPECIES.broadcast((int) 0), m).addAll();
 609     }
 610 
 611     @Override
 612     @ForceInline
 613     public int subAll(Mask<Integer, Shapes.S512Bit> m) {
 614         return blend(SPECIES.broadcast((int) 0), m).subAll();
 615     }
 616 
 617     @Override
 618     @ForceInline
 619     public int mulAll(Mask<Integer, Shapes.S512Bit> m) {
 620         return blend(SPECIES.broadcast((int) 1), m).mulAll();
 621     }
 622 
 623     @Override
 624     @ForceInline
 625     public int minAll(Mask<Integer, Shapes.S512Bit> m) {
 626         return blend(SPECIES.broadcast(Integer.MAX_VALUE), m).minAll();
 627     }
 628 
 629     @Override
 630     @ForceInline
 631     public int maxAll(Mask<Integer, Shapes.S512Bit> m) {
 632         return blend(SPECIES.broadcast(Integer.MIN_VALUE), m).maxAll();
 633     }
 634 
 635     @Override
 636     @ForceInline
 637     public Shuffle<Integer, Shapes.S512Bit> 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(Int512Vector.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.S512Bit> m) {
 665         // @@@ This can result in out of bounds errors for unset mask lanes
 666         Int512Vector oldVal = SPECIES.fromArray(a, ax);
 667         Int512Vector 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(Int512Vector.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.S512Bit> m) {
 691         // @@@ This can result in out of bounds errors for unset mask lanes
 692         Int512Vector oldVal = SPECIES.fromByteArray(a, ix);
 693         Int512Vector 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(Int512Vector.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.S512Bit> m) {
 722         // @@@ This can result in out of bounds errors for unset mask lanes
 723         Int512Vector oldVal = SPECIES.fromByteBuffer(bb, ix);
 724         Int512Vector 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         Int512Vector that = (Int512Vector) 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     Int512Mask bTest(Vector<Integer, Shapes.S512Bit> o, FBinTest f) {
 754         int[] vec1 = getElements();
 755         int[] vec2 = ((Int512Vector)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 Int512Mask(bits);
 761     }
 762 
 763     // Comparisons
 764 
 765     @Override
 766     @ForceInline
 767     public Int512Mask equal(Vector<Integer, Shapes.S512Bit> o) {
 768         Objects.requireNonNull(o);
 769         Int512Vector v = (Int512Vector)o;
 770 
 771         return VectorIntrinsics.compare(
 772             BT_eq, Int512Vector.class, Int512Mask.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 Int512Mask notEqual(Vector<Integer, Shapes.S512Bit> o) {
 780         Objects.requireNonNull(o);
 781         Int512Vector v = (Int512Vector)o;
 782 
 783         return VectorIntrinsics.compare(
 784             BT_ne, Int512Vector.class, Int512Mask.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 Int512Mask lessThan(Vector<Integer, Shapes.S512Bit> o) {
 792         Objects.requireNonNull(o);
 793         Int512Vector v = (Int512Vector)o;
 794 
 795         return VectorIntrinsics.compare(
 796             BT_lt, Int512Vector.class, Int512Mask.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 Int512Mask lessThanEq(Vector<Integer, Shapes.S512Bit> o) {
 804         Objects.requireNonNull(o);
 805         Int512Vector v = (Int512Vector)o;
 806 
 807         return VectorIntrinsics.compare(
 808             BT_le, Int512Vector.class, Int512Mask.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 Int512Mask greaterThan(Vector<Integer, Shapes.S512Bit> o) {
 816         Objects.requireNonNull(o);
 817         Int512Vector v = (Int512Vector)o;
 818 
 819         return (Int512Mask) VectorIntrinsics.compare(
 820             BT_gt, Int512Vector.class, Int512Mask.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 Int512Mask greaterThanEq(Vector<Integer, Shapes.S512Bit> o) {
 828         Objects.requireNonNull(o);
 829         Int512Vector v = (Int512Vector)o;
 830 
 831         return VectorIntrinsics.compare(
 832             BT_ge, Int512Vector.class, Int512Mask.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.S512Bit> o, FUnCon f) {
 849         boolean[] mbits = ((Int512Mask)o).getBits();
 850         forEach((i, a) -> {
 851             if (mbits[i]) { f.apply(i, a); }
 852         });
 853     }
 854 
 855 
 856     Float512Vector 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 Float512Vector(res);
 863     }
 864 
 865     @Override
 866     public Int512Vector 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 Int512Vector(res);
 873     }
 874 
 875     @Override
 876     public Int512Vector 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 Int512Vector(res);
 888     }
 889 
 890     @Override
 891     public Int512Vector 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 Int512Vector(res);
 898     }
 899 
 900     @Override
 901     public Int512Vector 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 Int512Vector(res);
 908     }
 909 
 910     @Override
 911     @ForceInline
 912     public Int512Vector rearrange(Vector<Integer, Shapes.S512Bit> v,
 913                                   Shuffle<Integer, Shapes.S512Bit> s, Mask<Integer, Shapes.S512Bit> m) {
 914         return this.rearrange(s).blend(v.rearrange(s), m);
 915     }
 916 
 917     @Override
 918     @ForceInline
 919     public Int512Vector rearrange(Shuffle<Integer, Shapes.S512Bit> o1) {
 920     Objects.requireNonNull(o1);
 921     Int512Shuffle s =  (Int512Shuffle)o1;
 922 
 923         return VectorIntrinsics.rearrangeOp(
 924             Int512Vector.class, Int512Shuffle.class, int.class, LENGTH,
 925             this, s,
 926             (v1, s_) -> v1.uOp((i, a) -> {
 927             int[] vec = this.getElements();
 928             int ei = s_.getElement(i);
 929             return vec[ei];
 930         }));
 931     }
 932 
 933     @Override
 934     @ForceInline
 935     public Int512Vector blend(Vector<Integer, Shapes.S512Bit> o1, Mask<Integer, Shapes.S512Bit> o2) {
 936         Objects.requireNonNull(o1);
 937         Objects.requireNonNull(o2);
 938         Int512Vector v = (Int512Vector)o1;
 939         Int512Mask   m = (Int512Mask)o2;
 940 
 941         return VectorIntrinsics.blend(
 942             Int512Vector.class, Int512Mask.class, int.class, LENGTH,
 943             this, v, m,
 944             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
 945     }
 946 
 947     // Accessors
 948 
 949     @Override
 950     public int get(int i) {
 951         if (i < 0 || i >= LENGTH) {
 952             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
 953         }
 954         return (int) VectorIntrinsics.extract(
 955                                 Int512Vector.class, int.class, LENGTH,
 956                                 this, i,
 957                                 (vec, ix) -> {
 958                                     int[] vecarr = vec.getElements();
 959                                     return (long)vecarr[ix];
 960                                 });
 961     }
 962 
 963     @Override
 964     public Int512Vector with(int i, int e) {
 965         if (i < 0 || i >= LENGTH) {
 966             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
 967         }
 968         return VectorIntrinsics.insert(
 969                                 Int512Vector.class, int.class, LENGTH,
 970                                 this, i, (long)e,
 971                                 (v, ix, bits) -> {
 972                                     int[] res = v.getElements().clone();
 973                                     res[ix] = (int)bits;
 974                                     return new Int512Vector(res);
 975                                 });
 976     }
 977 
 978     // Mask
 979 
 980     static final class Int512Mask extends AbstractMask<Integer, Shapes.S512Bit> {
 981         static final Int512Mask TRUE_MASK = new Int512Mask(true);
 982         static final Int512Mask FALSE_MASK = new Int512Mask(false);
 983 
 984         // FIXME: was temporarily put here to simplify rematerialization support in the JVM
 985         private final boolean[] bits; // Don't access directly, use getBits() instead.
 986 
 987         public Int512Mask(boolean[] bits) {
 988             this(bits, 0);
 989         }
 990 
 991         public Int512Mask(boolean[] bits, int offset) {
 992             boolean[] a = new boolean[species().length()];
 993             for (int i = 0; i < a.length; i++) {
 994                 a[i] = bits[offset + i];
 995             }
 996             this.bits = a;
 997         }
 998 
 999         public Int512Mask(boolean val) {
1000             boolean[] bits = new boolean[species().length()];
1001             Arrays.fill(bits, val);
1002             this.bits = bits;
1003         }
1004 
1005         boolean[] getBits() {
1006             return VectorIntrinsics.maybeRebox(this).bits;
1007         }
1008 
1009         @Override
1010         Int512Mask uOp(MUnOp f) {
1011             boolean[] res = new boolean[species().length()];
1012             boolean[] bits = getBits();
1013             for (int i = 0; i < species().length(); i++) {
1014                 res[i] = f.apply(i, bits[i]);
1015             }
1016             return new Int512Mask(res);
1017         }
1018 
1019         @Override
1020         Int512Mask bOp(Mask<Integer, Shapes.S512Bit> o, MBinOp f) {
1021             boolean[] res = new boolean[species().length()];
1022             boolean[] bits = getBits();
1023             boolean[] mbits = ((Int512Mask)o).getBits();
1024             for (int i = 0; i < species().length(); i++) {
1025                 res[i] = f.apply(i, bits[i], mbits[i]);
1026             }
1027             return new Int512Mask(res);
1028         }
1029 
1030         @Override
1031         public Int512Species species() {
1032             return SPECIES;
1033         }
1034 
1035         @Override
1036         public Int512Vector toVector() {
1037             int[] res = new int[species().length()];
1038             boolean[] bits = getBits();
1039             for (int i = 0; i < species().length(); i++) {
1040                 // -1 will result in the most significant bit being set in
1041                 // addition to some or all other bits
1042                 res[i] = (int) (bits[i] ? -1 : 0);
1043             }
1044             return new Int512Vector(res);
1045         }
1046 
1047         // Unary operations
1048 
1049         @Override
1050         @ForceInline
1051         public Int512Mask not() {
1052             return (Int512Mask) VectorIntrinsics.unaryOp(
1053                                              VECTOR_OP_NOT, Int512Mask.class, int.class, LENGTH,
1054                                              this,
1055                                              (m1) -> m1.uOp((i, a) -> !a));
1056         }
1057 
1058         // Binary operations
1059 
1060         @Override
1061         @ForceInline
1062         public Int512Mask and(Mask<Integer,Shapes.S512Bit> o) {
1063             Objects.requireNonNull(o);
1064             Int512Mask m = (Int512Mask)o;
1065             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Int512Mask.class, int.class, LENGTH,
1066                                              this, m,
1067                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1068         }
1069 
1070         @Override
1071         @ForceInline
1072         public Int512Mask or(Mask<Integer,Shapes.S512Bit> o) {
1073             Objects.requireNonNull(o);
1074             Int512Mask m = (Int512Mask)o;
1075             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Int512Mask.class, int.class, LENGTH,
1076                                              this, m,
1077                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1078         }
1079 
1080         // Reductions
1081 
1082         @Override
1083         @ForceInline
1084         public boolean anyTrue() {
1085             return VectorIntrinsics.test(COND_notZero, Int512Mask.class, int.class, LENGTH,
1086                                          this, this,
1087                                          (m1, m2) -> super.anyTrue());
1088         }
1089 
1090         @Override
1091         @ForceInline
1092         public boolean allTrue() {
1093             return VectorIntrinsics.test(COND_carrySet, Int512Mask.class, int.class, LENGTH,
1094                                          this, species().maskAllTrue(),
1095                                          (m1, m2) -> super.allTrue());
1096         }
1097     }
1098 
1099     // Shuffle
1100 
1101     static final class Int512Shuffle extends AbstractShuffle<Integer, Shapes.S512Bit> {
1102         Int512Shuffle(byte[] reorder) {
1103             super(reorder);
1104         }
1105 
1106         public Int512Shuffle(int[] reorder) {
1107             super(reorder);
1108         }
1109 
1110         public Int512Shuffle(int[] reorder, int i) {
1111             super(reorder, i);
1112         }
1113 
1114         public Int512Shuffle(IntUnaryOperator f) {
1115             super(f);
1116         }
1117 
1118         @Override
1119         public Int512Species species() {
1120             return SPECIES;
1121         }
1122 
1123         @Override
1124         public Int512Vector toVector() {
1125             int[] va = new int[SPECIES.length()];
1126             for (int i = 0; i < va.length; i++) {
1127               va[i] = (int) getElement(i);
1128             }
1129             return species().fromArray(va, 0);
1130         }
1131 
1132         @Override
1133         public Int512Shuffle rearrange(Vector.Shuffle<Integer, Shapes.S512Bit> o) {
1134             Int512Shuffle s = (Int512Shuffle) o;
1135             byte[] r = new byte[reorder.length];
1136             for (int i = 0; i < reorder.length; i++) {
1137                 r[i] = reorder[s.reorder[i]];
1138             }
1139             return new Int512Shuffle(r);
1140         }
1141     }
1142 
1143     // Species
1144 
1145     @Override
1146     public Int512Species species() {
1147         return SPECIES;
1148     }
1149 
1150     static final class Int512Species extends IntSpecies<Shapes.S512Bit> {
1151         static final int BIT_SIZE = Shapes.S_512_BIT.bitSize();
1152 
1153         static final int LENGTH = BIT_SIZE / Integer.SIZE;
1154 
1155         @Override
1156         public String toString() {
1157            StringBuilder sb = new StringBuilder("Shape[");
1158            sb.append(bitSize()).append(" bits, ");
1159            sb.append(length()).append(" ").append(int.class.getSimpleName()).append("s x ");
1160            sb.append(elementSize()).append(" bits");
1161            sb.append("]");
1162            return sb.toString();
1163         }
1164 
1165         @Override
1166         @ForceInline
1167         public int bitSize() {
1168             return BIT_SIZE;
1169         }
1170 
1171         @Override
1172         @ForceInline
1173         public int length() {
1174             return LENGTH;
1175         }
1176 
1177         @Override
1178         @ForceInline
1179         public Class<Integer> elementType() {
1180             return int.class;
1181         }
1182 
1183         @Override
1184         @ForceInline
1185         public int elementSize() {
1186             return Integer.SIZE;
1187         }
1188 
1189         @Override
1190         @ForceInline
1191         public Shapes.S512Bit shape() {
1192             return Shapes.S_512_BIT;
1193         }
1194 
1195         @Override
1196         Int512Vector op(FOp f) {
1197             int[] res = new int[length()];
1198             for (int i = 0; i < length(); i++) {
1199                 res[i] = f.apply(i);
1200             }
1201             return new Int512Vector(res);
1202         }
1203 
1204         @Override
1205         Int512Vector op(Mask<Integer, Shapes.S512Bit> o, FOp f) {
1206             int[] res = new int[length()];
1207             boolean[] mbits = ((Int512Mask)o).getBits();
1208             for (int i = 0; i < length(); i++) {
1209                 if (mbits[i]) {
1210                     res[i] = f.apply(i);
1211                 }
1212             }
1213             return new Int512Vector(res);
1214         }
1215 
1216         // Factories
1217 
1218         @Override
1219         public Int512Mask maskFromValues(boolean... bits) {
1220             return new Int512Mask(bits);
1221         }
1222 
1223         @Override
1224         public Int512Mask maskFromArray(boolean[] bits, int i) {
1225             return new Int512Mask(bits, i);
1226         }
1227 
1228         @Override
1229         public Int512Shuffle shuffle(IntUnaryOperator f) {
1230             return new Int512Shuffle(f);
1231         }
1232 
1233         @Override
1234         public Int512Shuffle shuffleIota() {
1235             return new Int512Shuffle(AbstractShuffle.IDENTITY);
1236         }
1237 
1238         @Override
1239         public Int512Shuffle shuffleFromValues(int... ixs) {
1240             return new Int512Shuffle(ixs);
1241         }
1242 
1243         @Override
1244         public Int512Shuffle shuffleFromArray(int[] ixs, int i) {
1245             return new Int512Shuffle(ixs, i);
1246         }
1247 
1248         @Override
1249         @ForceInline
1250         public Int512Vector zero() {
1251             return VectorIntrinsics.broadcastCoerced(Int512Vector.class, int.class, LENGTH,
1252                                                      0,
1253                                                      (z -> ZERO));
1254         }
1255 
1256         @Override
1257         @ForceInline
1258         public Int512Vector broadcast(int e) {
1259             return VectorIntrinsics.broadcastCoerced(
1260                 Int512Vector.class, int.class, LENGTH,
1261                 e,
1262                 ((long bits) -> SPECIES.op(i -> (int)bits)));
1263         }
1264 
1265         @Override
1266         @ForceInline
1267         public Int512Mask maskAllTrue() {
1268             return VectorIntrinsics.broadcastCoerced(Int512Mask.class, int.class, LENGTH,
1269                                                      (int)-1,
1270                                                      (z -> Int512Mask.TRUE_MASK));
1271         }
1272 
1273         @Override
1274         @ForceInline
1275         public Int512Mask maskAllFalse() {
1276             return VectorIntrinsics.broadcastCoerced(Int512Mask.class, int.class, LENGTH,
1277                                                      0,
1278                                                      (z -> Int512Mask.FALSE_MASK));
1279         }
1280 
1281         @Override
1282         @ForceInline
1283         public Int512Vector scalars(int... es) {
1284             Objects.requireNonNull(es);
1285             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1286             return VectorIntrinsics.load(Int512Vector.class, int.class, LENGTH,
1287                                          es, Unsafe.ARRAY_INT_BASE_OFFSET,
1288                                          es, ix,
1289                                          (c, idx) -> op(n -> c[idx + n]));
1290         }
1291 
1292         @Override
1293         @ForceInline
1294         public Int512Vector fromArray(int[] a, int ix) {
1295             Objects.requireNonNull(a);
1296             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1297             return VectorIntrinsics.load(Int512Vector.class, int.class, LENGTH,
1298                                          a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
1299                                          a, ix,
1300                                          (c, idx) -> op(n -> c[idx + n]));
1301         }
1302 
1303         @Override
1304         @ForceInline
1305         public Int512Vector fromArray(int[] a, int ax, Mask<Integer, Shapes.S512Bit> m) {
1306             // @@@ This can result in out of bounds errors for unset mask lanes
1307             return zero().blend(fromArray(a, ax), m);
1308         }
1309 
1310         @Override
1311         @ForceInline
1312         public Int512Vector fromByteArray(byte[] a, int ix) {
1313             // @@@ Endianess
1314             Objects.requireNonNull(a);
1315             ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
1316             return VectorIntrinsics.load(Int512Vector.class, int.class, LENGTH,
1317                                          a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
1318                                          a, ix,
1319                                          (c, idx) -> {
1320                                              ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
1321                                              IntBuffer tb = bbc.asIntBuffer();
1322                                              return op(i -> tb.get());
1323                                          });
1324         }
1325 
1326         @Override
1327         @ForceInline
1328         public Int512Vector fromByteArray(byte[] a, int ix, Mask<Integer, Shapes.S512Bit> m) {
1329             // @@@ This can result in out of bounds errors for unset mask lanes
1330             return zero().blend(fromByteArray(a, ix), m);
1331         }
1332 
1333         @Override
1334         @ForceInline
1335         public Int512Vector fromByteBuffer(ByteBuffer bb, int ix) {
1336             // @@@ Endianess
1337             if (bb.order() != ByteOrder.nativeOrder()) {
1338                 throw new IllegalArgumentException();
1339             }
1340             ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
1341             return VectorIntrinsics.load(Int512Vector.class, int.class, LENGTH,
1342                                          U.getObject(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
1343                                          bb, ix,
1344                                          (c, idx) -> {
1345                                              ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
1346                                              IntBuffer tb = bbc.asIntBuffer();
1347                                              return op(i -> tb.get());
1348                                          });
1349         }
1350 
1351         @Override
1352         @ForceInline
1353         public Int512Vector fromByteBuffer(ByteBuffer bb, int ix, Mask<Integer, Shapes.S512Bit> m) {
1354             // @@@ This can result in out of bounds errors for unset mask lanes
1355             return zero().blend(fromByteBuffer(bb, ix), m);
1356         }
1357 
1358         @Override
1359         @ForceInline
1360         @SuppressWarnings("unchecked")
1361         public <F, T extends Shape> Int512Vector cast(Vector<F, T> o) {
1362             if (o.length() != LENGTH)
1363                 throw new IllegalArgumentException("Vector length this species length differ");
1364 
1365             return VectorIntrinsics.cast(
1366                 o.getClass(),
1367                 o.elementType(), LENGTH,
1368                 int.class, LENGTH,
1369                 o, this,
1370                 (s, v) -> s.castDefault(v)
1371             );
1372         }
1373 
1374         @SuppressWarnings("unchecked")
1375         @ForceInline
1376         private <F, T extends Shape> Int512Vector castDefault(Vector<F, T> v) {
1377             // Allocate array of required size
1378             int limit = length();
1379             int[] a = new int[limit];
1380 
1381             Class<?> vtype = v.species().elementType();
1382             if (vtype == byte.class) {
1383                 ByteVector<T> tv = (ByteVector<T>)v;
1384                 for (int i = 0; i < limit; i++) {
1385                     a[i] = (int) tv.get(i);
1386                 }
1387             } else if (vtype == short.class) {
1388                 ShortVector<T> tv = (ShortVector<T>)v;
1389                 for (int i = 0; i < limit; i++) {
1390                     a[i] = (int) tv.get(i);
1391                 }
1392             } else if (vtype == int.class) {
1393                 IntVector<T> tv = (IntVector<T>)v;
1394                 for (int i = 0; i < limit; i++) {
1395                     a[i] = (int) tv.get(i);
1396                 }
1397             } else if (vtype == long.class){
1398                 LongVector<T> tv = (LongVector<T>)v;
1399                 for (int i = 0; i < limit; i++) {
1400                     a[i] = (int) tv.get(i);
1401                 }
1402             } else if (vtype == float.class){
1403                 FloatVector<T> tv = (FloatVector<T>)v;
1404                 for (int i = 0; i < limit; i++) {
1405                     a[i] = (int) tv.get(i);
1406                 }
1407             } else if (vtype == double.class){
1408                 DoubleVector<T> tv = (DoubleVector<T>)v;
1409                 for (int i = 0; i < limit; i++) {
1410                     a[i] = (int) tv.get(i);
1411                 }
1412             } else {
1413                 throw new UnsupportedOperationException("Bad lane type for casting.");
1414             }
1415 
1416             return scalars(a);
1417         }
1418 
1419         @Override
1420         @ForceInline
1421         public <E, S extends Shape> Int512Mask cast(Mask<E, S> m) {
1422             if (m.length() != LENGTH)
1423                 throw new IllegalArgumentException("Mask length this species length differ");
1424             return new Int512Mask(m.toArray());
1425         }
1426 
1427         @Override
1428         @ForceInline
1429         public <E, S extends Shape> Int512Shuffle cast(Shuffle<E, S> s) {
1430             if (s.length() != LENGTH)
1431                 throw new IllegalArgumentException("Shuffle length this species length differ");
1432             return new Int512Shuffle(s.toArray());
1433         }
1434 
1435         @Override
1436         @ForceInline
1437         @SuppressWarnings("unchecked")
1438         public <F> Int512Vector rebracket(Vector<F, Shapes.S512Bit> o) {
1439             Objects.requireNonNull(o);
1440             if (o.elementType() == byte.class) {
1441                 Byte512Vector so = (Byte512Vector)o;
1442                 return VectorIntrinsics.reinterpret(
1443                     Byte512Vector.class,
1444                     byte.class, so.length(),
1445                     int.class, LENGTH,
1446                     so, this,
1447                     (s, v) -> (Int512Vector) s.reshape(v)
1448                 );
1449             } else if (o.elementType() == short.class) {
1450                 Short512Vector so = (Short512Vector)o;
1451                 return VectorIntrinsics.reinterpret(
1452                     Short512Vector.class,
1453                     short.class, so.length(),
1454                     int.class, LENGTH,
1455                     so, this,
1456                     (s, v) -> (Int512Vector) s.reshape(v)
1457                 );
1458             } else if (o.elementType() == int.class) {
1459                 Int512Vector so = (Int512Vector)o;
1460                 return VectorIntrinsics.reinterpret(
1461                     Int512Vector.class,
1462                     int.class, so.length(),
1463                     int.class, LENGTH,
1464                     so, this,
1465                     (s, v) -> (Int512Vector) s.reshape(v)
1466                 );
1467             } else if (o.elementType() == long.class) {
1468                 Long512Vector so = (Long512Vector)o;
1469                 return VectorIntrinsics.reinterpret(
1470                     Long512Vector.class,
1471                     long.class, so.length(),
1472                     int.class, LENGTH,
1473                     so, this,
1474                     (s, v) -> (Int512Vector) s.reshape(v)
1475                 );
1476             } else if (o.elementType() == float.class) {
1477                 Float512Vector so = (Float512Vector)o;
1478                 return VectorIntrinsics.reinterpret(
1479                     Float512Vector.class,
1480                     float.class, so.length(),
1481                     int.class, LENGTH,
1482                     so, this,
1483                     (s, v) -> (Int512Vector) s.reshape(v)
1484                 );
1485             } else if (o.elementType() == double.class) {
1486                 Double512Vector so = (Double512Vector)o;
1487                 return VectorIntrinsics.reinterpret(
1488                     Double512Vector.class,
1489                     double.class, so.length(),
1490                     int.class, LENGTH,
1491                     so, this,
1492                     (s, v) -> (Int512Vector) s.reshape(v)
1493                 );
1494             } else {
1495                 throw new InternalError("Unimplemented type");
1496             }
1497         }
1498 
1499         @Override
1500         @ForceInline
1501         @SuppressWarnings("unchecked")
1502         public <T extends Shape> Int512Vector resize(Vector<Integer, T> o) {
1503             Objects.requireNonNull(o);
1504             if (o.bitSize() == 64) {
1505                 Int64Vector so = (Int64Vector)o;
1506                 return VectorIntrinsics.reinterpret(
1507                     Int64Vector.class,
1508                     int.class, so.length(),
1509                     int.class, LENGTH,
1510                     so, this,
1511                     (s, v) -> (Int512Vector) s.reshape(v)
1512                 );
1513             } else if (o.bitSize() == 128) {
1514                 Int128Vector so = (Int128Vector)o;
1515                 return VectorIntrinsics.reinterpret(
1516                     Int128Vector.class,
1517                     int.class, so.length(),
1518                     int.class, LENGTH,
1519                     so, this,
1520                     (s, v) -> (Int512Vector) s.reshape(v)
1521                 );
1522             } else if (o.bitSize() == 256) {
1523                 Int256Vector so = (Int256Vector)o;
1524                 return VectorIntrinsics.reinterpret(
1525                     Int256Vector.class,
1526                     int.class, so.length(),
1527                     int.class, LENGTH,
1528                     so, this,
1529                     (s, v) -> (Int512Vector) s.reshape(v)
1530                 );
1531             } else if (o.bitSize() == 512) {
1532                 Int512Vector so = (Int512Vector)o;
1533                 return VectorIntrinsics.reinterpret(
1534                     Int512Vector.class,
1535                     int.class, so.length(),
1536                     int.class, LENGTH,
1537                     so, this,
1538                     (s, v) -> (Int512Vector) s.reshape(v)
1539                 );
1540             } else {
1541                 throw new InternalError("Unimplemented size");
1542             }
1543         }
1544     }
1545 }
--- EOF ---