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