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 Float128Vector extends FloatVector {
  41     static final Float128Species SPECIES = new Float128Species();
  42 
  43     static final Float128Vector ZERO = new Float128Vector();
  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     Float128Vector() {
  61         vec = new float[SPECIES.length()];
  62     }
  63 
  64     Float128Vector(float[] v) {
  65         vec = v;
  66     }
  67 
  68     @Override
  69     public int length() { return LENGTH; }
  70 
  71     // Unary operator
  72 
  73     @Override
  74     Float128Vector 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 Float128Vector(res);
  81     }
  82 
  83     @Override
  84     Float128Vector uOp(Mask<Float> o, FUnOp f) {
  85         float[] vec = getElements();
  86         float[] res = new float[length()];
  87         boolean[] mbits = ((Float128Mask)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 Float128Vector(res);
  92     }
  93 
  94     // Binary operator
  95 
  96     @Override
  97     Float128Vector bOp(Vector<Float> o, FBinOp f) {
  98         float[] res = new float[length()];
  99         float[] vec1 = this.getElements();
 100         float[] vec2 = ((Float128Vector)o).getElements();
 101         for (int i = 0; i < length(); i++) {
 102             res[i] = f.apply(i, vec1[i], vec2[i]);
 103         }
 104         return new Float128Vector(res);
 105     }
 106 
 107     @Override
 108     Float128Vector bOp(Vector<Float> o1, Mask<Float> o2, FBinOp f) {
 109         float[] res = new float[length()];
 110         float[] vec1 = this.getElements();
 111         float[] vec2 = ((Float128Vector)o1).getElements();
 112         boolean[] mbits = ((Float128Mask)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 Float128Vector(res);
 117     }
 118 
 119     // Trinary operator
 120 
 121     @Override
 122     Float128Vector tOp(Vector<Float> o1, Vector<Float> o2, FTriOp f) {
 123         float[] res = new float[length()];
 124         float[] vec1 = this.getElements();
 125         float[] vec2 = ((Float128Vector)o1).getElements();
 126         float[] vec3 = ((Float128Vector)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 Float128Vector(res);
 131     }
 132 
 133     @Override
 134     Float128Vector 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 = ((Float128Vector)o1).getElements();
 138         float[] vec3 = ((Float128Vector)o2).getElements();
 139         boolean[] mbits = ((Float128Mask)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 Float128Vector(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             Float128Vector.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                 Float128Vector.class,
 243                 float.class, LENGTH,
 244                 Byte128Vector.class,
 245                 byte.class, Byte128Vector.LENGTH,
 246                 this, s,
 247                 (species, vector) -> vector.defaultReinterpret(species)
 248             );
 249         } else if (stype == short.class) {
 250             return VectorIntrinsics.reinterpret(
 251                 Float128Vector.class,
 252                 float.class, LENGTH,
 253                 Short128Vector.class,
 254                 short.class, Short128Vector.LENGTH,
 255                 this, s,
 256                 (species, vector) -> vector.defaultReinterpret(species)
 257             );
 258         } else if (stype == int.class) {
 259             return VectorIntrinsics.reinterpret(
 260                 Float128Vector.class,
 261                 float.class, LENGTH,
 262                 Int128Vector.class,
 263                 int.class, Int128Vector.LENGTH,
 264                 this, s,
 265                 (species, vector) -> vector.defaultReinterpret(species)
 266             );
 267         } else if (stype == long.class) {
 268             return VectorIntrinsics.reinterpret(
 269                 Float128Vector.class,
 270                 float.class, LENGTH,
 271                 Long128Vector.class,
 272                 long.class, Long128Vector.LENGTH,
 273                 this, s,
 274                 (species, vector) -> vector.defaultReinterpret(species)
 275             );
 276         } else if (stype == float.class) {
 277             return VectorIntrinsics.reinterpret(
 278                 Float128Vector.class,
 279                 float.class, LENGTH,
 280                 Float128Vector.class,
 281                 float.class, Float128Vector.LENGTH,
 282                 this, s,
 283                 (species, vector) -> vector.defaultReinterpret(species)
 284             );
 285         } else if (stype == double.class) {
 286             return VectorIntrinsics.reinterpret(
 287                 Float128Vector.class,
 288                 float.class, LENGTH,
 289                 Double128Vector.class,
 290                 double.class, Double128Vector.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                 Float128Vector.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                 Float128Vector.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                 Float128Vector.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                 Float128Vector.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                 Float128Vector.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 Float128Vector 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 Float128Vector neg(Mask<Float> m) {
 523         return blend(neg(), m);
 524     }
 525 
 526     @Override
 527     @ForceInline
 528     public Float128Vector abs() {
 529         return VectorIntrinsics.unaryOp(
 530             VECTOR_OP_ABS, Float128Vector.class, float.class, LENGTH,
 531             this,
 532             v1 -> v1.uOp((i, a) -> (float) Math.abs(a)));
 533     }
 534 
 535     @ForceInline
 536     @Override
 537     public Float128Vector abs(Mask<Float> m) {
 538         return blend(abs(), m);
 539     }
 540 
 541     @Override
 542     @ForceInline
 543     public Float128Vector neg() {
 544         return VectorIntrinsics.unaryOp(
 545             VECTOR_OP_NEG, Float128Vector.class, float.class, LENGTH,
 546             this,
 547             v1 -> v1.uOp((i, a) -> (float) -a));
 548     }
 549 
 550     @Override
 551     @ForceInline
 552     public Float128Vector div(Vector<Float> o) {
 553         Objects.requireNonNull(o);
 554         Float128Vector v = (Float128Vector)o;
 555         return VectorIntrinsics.binaryOp(
 556             VECTOR_OP_DIV, Float128Vector.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 Float128Vector sqrt() {
 564         return VectorIntrinsics.unaryOp(
 565             VECTOR_OP_SQRT, Float128Vector.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 Float128Vector exp() {
 573         return (Float128Vector) VectorIntrinsics.unaryOp(
 574             VECTOR_OP_EXP, Float128Vector.class, float.class, LENGTH,
 575             this,
 576             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.exp((double) a)));
 577     }
 578 
 579     @Override
 580     @ForceInline
 581     public Float128Vector log1p() {
 582         return (Float128Vector) VectorIntrinsics.unaryOp(
 583             VECTOR_OP_LOG1P, Float128Vector.class, float.class, LENGTH,
 584             this,
 585             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.log1p((double) a)));
 586     }
 587 
 588     @Override
 589     @ForceInline
 590     public Float128Vector log() {
 591         return (Float128Vector) VectorIntrinsics.unaryOp(
 592             VECTOR_OP_LOG, Float128Vector.class, float.class, LENGTH,
 593             this,
 594             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.log((double) a)));
 595     }
 596 
 597     @Override
 598     @ForceInline
 599     public Float128Vector log10() {
 600         return (Float128Vector) VectorIntrinsics.unaryOp(
 601             VECTOR_OP_LOG10, Float128Vector.class, float.class, LENGTH,
 602             this,
 603             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.log10((double) a)));
 604     }
 605 
 606     @Override
 607     @ForceInline
 608     public Float128Vector expm1() {
 609         return (Float128Vector) VectorIntrinsics.unaryOp(
 610             VECTOR_OP_EXPM1, Float128Vector.class, float.class, LENGTH,
 611             this,
 612             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.expm1((double) a)));
 613     }
 614 
 615     @Override
 616     @ForceInline
 617     public Float128Vector cbrt() {
 618         return (Float128Vector) VectorIntrinsics.unaryOp(
 619             VECTOR_OP_CBRT, Float128Vector.class, float.class, LENGTH,
 620             this,
 621             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.cbrt((double) a)));
 622     }
 623 
 624     @Override
 625     @ForceInline
 626     public Float128Vector sin() {
 627         return (Float128Vector) VectorIntrinsics.unaryOp(
 628             VECTOR_OP_SIN, Float128Vector.class, float.class, LENGTH,
 629             this,
 630             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.sin((double) a)));
 631     }
 632 
 633     @Override
 634     @ForceInline
 635     public Float128Vector cos() {
 636         return (Float128Vector) VectorIntrinsics.unaryOp(
 637             VECTOR_OP_COS, Float128Vector.class, float.class, LENGTH,
 638             this,
 639             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.cos((double) a)));
 640     }
 641 
 642     @Override
 643     @ForceInline
 644     public Float128Vector tan() {
 645         return (Float128Vector) VectorIntrinsics.unaryOp(
 646             VECTOR_OP_TAN, Float128Vector.class, float.class, LENGTH,
 647             this,
 648             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.tan((double) a)));
 649     }
 650 
 651     @Override
 652     @ForceInline
 653     public Float128Vector asin() {
 654         return (Float128Vector) VectorIntrinsics.unaryOp(
 655             VECTOR_OP_ASIN, Float128Vector.class, float.class, LENGTH,
 656             this,
 657             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.asin((double) a)));
 658     }
 659 
 660     @Override
 661     @ForceInline
 662     public Float128Vector acos() {
 663         return (Float128Vector) VectorIntrinsics.unaryOp(
 664             VECTOR_OP_ACOS, Float128Vector.class, float.class, LENGTH,
 665             this,
 666             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.acos((double) a)));
 667     }
 668 
 669     @Override
 670     @ForceInline
 671     public Float128Vector atan() {
 672         return (Float128Vector) VectorIntrinsics.unaryOp(
 673             VECTOR_OP_ATAN, Float128Vector.class, float.class, LENGTH,
 674             this,
 675             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.atan((double) a)));
 676     }
 677 
 678     @Override
 679     @ForceInline
 680     public Float128Vector sinh() {
 681         return (Float128Vector) VectorIntrinsics.unaryOp(
 682             VECTOR_OP_SINH, Float128Vector.class, float.class, LENGTH,
 683             this,
 684             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.sinh((double) a)));
 685     }
 686 
 687     @Override
 688     @ForceInline
 689     public Float128Vector cosh() {
 690         return (Float128Vector) VectorIntrinsics.unaryOp(
 691             VECTOR_OP_COSH, Float128Vector.class, float.class, LENGTH,
 692             this,
 693             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.cosh((double) a)));
 694     }
 695 
 696     @Override
 697     @ForceInline
 698     public Float128Vector tanh() {
 699         return (Float128Vector) VectorIntrinsics.unaryOp(
 700             VECTOR_OP_TANH, Float128Vector.class, float.class, LENGTH,
 701             this,
 702             v1 -> ((Float128Vector)v1).uOp((i, a) -> (float) Math.tanh((double) a)));
 703     }
 704 
 705     @Override
 706     @ForceInline
 707     public Float128Vector pow(Vector<Float> o) {
 708         Objects.requireNonNull(o);
 709         Float128Vector v = (Float128Vector)o;
 710         return (Float128Vector) VectorIntrinsics.binaryOp(
 711             VECTOR_OP_POW, Float128Vector.class, float.class, LENGTH,
 712             this, v,
 713             (v1, v2) -> ((Float128Vector)v1).bOp(v2, (i, a, b) -> (float)(Math.pow(a,b))));
 714     }
 715 
 716     @Override
 717     @ForceInline
 718     public Float128Vector hypot(Vector<Float> o) {
 719         Objects.requireNonNull(o);
 720         Float128Vector v = (Float128Vector)o;
 721         return (Float128Vector) VectorIntrinsics.binaryOp(
 722             VECTOR_OP_HYPOT, Float128Vector.class, float.class, LENGTH,
 723             this, v,
 724             (v1, v2) -> ((Float128Vector)v1).bOp(v2, (i, a, b) -> (float)(Math.hypot(a,b))));
 725     }
 726 
 727     @Override
 728     @ForceInline
 729     public Float128Vector atan2(Vector<Float> o) {
 730         Objects.requireNonNull(o);
 731         Float128Vector v = (Float128Vector)o;
 732         return (Float128Vector) VectorIntrinsics.binaryOp(
 733             VECTOR_OP_ATAN2, Float128Vector.class, float.class, LENGTH,
 734             this, v,
 735             (v1, v2) -> ((Float128Vector)v1).bOp(v2, (i, a, b) -> (float)(Math.atan2(a,b))));
 736     }
 737 
 738 
 739     // Binary operations
 740 
 741     @Override
 742     @ForceInline
 743     public Float128Vector add(Vector<Float> o) {
 744         Objects.requireNonNull(o);
 745         Float128Vector v = (Float128Vector)o;
 746         return VectorIntrinsics.binaryOp(
 747             VECTOR_OP_ADD, Float128Vector.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 Float128Vector add(Vector<Float> v, Mask<Float> m) {
 755         return blend(add(v), m);
 756     }
 757 
 758     @Override
 759     @ForceInline
 760     public Float128Vector sub(Vector<Float> o) {
 761         Objects.requireNonNull(o);
 762         Float128Vector v = (Float128Vector)o;
 763         return VectorIntrinsics.binaryOp(
 764             VECTOR_OP_SUB, Float128Vector.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 Float128Vector sub(Vector<Float> v, Mask<Float> m) {
 772         return blend(sub(v), m);
 773     }
 774 
 775     @Override
 776     @ForceInline
 777     public Float128Vector mul(Vector<Float> o) {
 778         Objects.requireNonNull(o);
 779         Float128Vector v = (Float128Vector)o;
 780         return VectorIntrinsics.binaryOp(
 781             VECTOR_OP_MUL, Float128Vector.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 Float128Vector mul(Vector<Float> v, Mask<Float> m) {
 789         return blend(mul(v), m);
 790     }
 791 
 792     @Override
 793     @ForceInline
 794     public Float128Vector min(Vector<Float> o) {
 795         Objects.requireNonNull(o);
 796         Float128Vector v = (Float128Vector)o;
 797         return (Float128Vector) VectorIntrinsics.binaryOp(
 798             VECTOR_OP_MIN, Float128Vector.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 Float128Vector min(Vector<Float> v, Mask<Float> m) {
 806         return blend(min(v), m);
 807     }
 808 
 809     @Override
 810     @ForceInline
 811     public Float128Vector max(Vector<Float> o) {
 812         Objects.requireNonNull(o);
 813         Float128Vector v = (Float128Vector)o;
 814         return VectorIntrinsics.binaryOp(
 815             VECTOR_OP_MAX, Float128Vector.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 Float128Vector 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 Float128Vector fma(Vector<Float> o1, Vector<Float> o2) {
 832         Objects.requireNonNull(o1);
 833         Objects.requireNonNull(o2);
 834         Float128Vector v1 = (Float128Vector)o1;
 835         Float128Vector v2 = (Float128Vector)o2;
 836         return VectorIntrinsics.ternaryOp(
 837             VECTOR_OP_FMA, Float128Vector.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, Float128Vector.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 mulAll() {
 860         int bits = (int) VectorIntrinsics.reductionCoerced(
 861                                 VECTOR_OP_MUL, Float128Vector.class, float.class, LENGTH,
 862                                 this,
 863                                 v -> {
 864                                     float r = v.rOp((float) 1, (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 minAll() {
 873         int bits = (int) VectorIntrinsics.reductionCoerced(
 874                                 VECTOR_OP_MIN, Float128Vector.class, float.class, LENGTH,
 875                                 this,
 876                                 v -> {
 877                                     float r = v.rOp(Float.MAX_VALUE , (i, a, b) -> (float) Math.min(a, b));
 878                                     return (long)Float.floatToIntBits(r);
 879                                 });
 880         return Float.intBitsToFloat(bits);
 881     }
 882 
 883     @Override
 884     @ForceInline
 885     public float maxAll() {
 886         int bits = (int) VectorIntrinsics.reductionCoerced(
 887                                 VECTOR_OP_MAX, Float128Vector.class, float.class, LENGTH,
 888                                 this,
 889                                 v -> {
 890                                     float r = v.rOp(Float.MIN_VALUE , (i, a, b) -> (float) Math.max(a, b));
 891                                     return (long)Float.floatToIntBits(r);
 892                                 });
 893         return Float.intBitsToFloat(bits);
 894     }
 895 
 896 
 897     @Override
 898     @ForceInline
 899     public float addAll(Mask<Float> m) {
 900         return SPECIES.broadcast((float) 0).blend(this, m).addAll();
 901     }
 902 
 903 
 904     @Override
 905     @ForceInline
 906     public float mulAll(Mask<Float> m) {
 907         return SPECIES.broadcast((float) 1).blend(this, m).mulAll();
 908     }
 909 
 910     @Override
 911     @ForceInline
 912     public float minAll(Mask<Float> m) {
 913         return SPECIES.broadcast(Float.MAX_VALUE).blend(this, m).minAll();
 914     }
 915 
 916     @Override
 917     @ForceInline
 918     public float maxAll(Mask<Float> m) {
 919         return SPECIES.broadcast(Float.MIN_VALUE).blend(this, m).maxAll();
 920     }
 921 
 922     @Override
 923     @ForceInline
 924     public Shuffle<Float> toShuffle() {
 925         float[] a = toArray();
 926         int[] sa = new int[a.length];
 927         for (int i = 0; i < a.length; i++) {
 928             sa[i] = (int) a[i];
 929         }
 930         return FloatVector.shuffleFromArray(SPECIES, sa, 0);
 931     }
 932 
 933     // Memory operations
 934 
 935     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_FLOAT_INDEX_SCALE);
 936     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
 937 
 938     @Override
 939     @ForceInline
 940     public void intoArray(float[] a, int ix) {
 941         Objects.requireNonNull(a);
 942         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 943         intoArrayWithoutCheck(a, ix);
 944     }
 945 
 946     @ForceInline
 947     private void intoArrayWithoutCheck(float[] a, int ix) {
 948         VectorIntrinsics.store(Float128Vector.class, float.class, LENGTH,
 949                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_FLOAT_BASE_OFFSET,
 950                                this,
 951                                a, ix,
 952                                (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
 953     }
 954 
 955     @Override
 956     @ForceInline
 957     public final void intoArray(float[] a, int ax, Mask<Float> m) {
 958         Objects.requireNonNull(a);
 959         if (ax + LENGTH <= a.length) {
 960             FloatVector oldVal = FloatVector.fromArrayWithoutCheck(SPECIES, a, ax);
 961             FloatVector newVal = oldVal.blend(this, m);
 962             ((Float128Vector)newVal).intoArrayWithoutCheck(a, ax);
 963         } else {
 964             forEach(m, (i, e) -> a[ax + i] = e);
 965         }
 966     }
 967 
 968     @Override
 969     @ForceInline
 970     public void intoArray(float[] a, int ix, int[] b, int iy) {
 971         Objects.requireNonNull(a);
 972         Objects.requireNonNull(b);
 973 
 974         // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
 975         IntVector vix = IntVector.fromArray(INDEX_SPEC, b, iy).add(ix);
 976 
 977         vix = VectorIntrinsics.checkIndex(vix, a.length);
 978 
 979         intoArrayWithoutCheck(a, ix, b, iy, vix);
 980     }
 981 
 982     @ForceInline
 983     private void intoArrayWithoutCheck(float[] a, int ix, int[] b, int iy, IntVector vix) {
 984         VectorIntrinsics.storeWithMap(Float128Vector.class, float.class, LENGTH, Int128Vector.class,
 985                                a, Unsafe.ARRAY_FLOAT_BASE_OFFSET, vix,
 986                                this,
 987                                a, ix, b, iy,
 988                                (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
 989     }
 990 
 991     @Override
 992     @ForceInline
 993     public final void intoArray(float[] a, int ax, Mask<Float> m, int[] b, int iy) {
 994         Objects.requireNonNull(a);
 995         Objects.requireNonNull(b);
 996 
 997         // Index vector: vix[0:n] = i -> ax + b[iy + i]
 998         IntVector vix = IntVector.fromArray(INDEX_SPEC, b, iy).add(ax);
 999 
1000         if(vix.lessThan(0).anyTrue() || vix.greaterThanEq(a.length).anyTrue()) {
1001             forEach(m, (i, e) -> a[ax + b[iy+i]] = e);
1002         } else {
1003             FloatVector oldVal = FloatVector.fromArrayWithoutCheck(SPECIES, a, ax, b, iy, vix);
1004             FloatVector newVal = oldVal.blend(this, m);
1005             ((Float128Vector)newVal).intoArrayWithoutCheck(a, ax, b, iy, vix);
1006         }
1007     }
1008 
1009     @Override
1010     @ForceInline
1011     public void intoByteArray(byte[] a, int ix) {
1012         Objects.requireNonNull(a);
1013         ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
1014         VectorIntrinsics.store(Float128Vector.class, float.class, LENGTH,
1015                                a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
1016                                this,
1017                                a, ix,
1018                                (c, idx, v) -> {
1019                                    ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
1020                                    FloatBuffer tb = bbc.asFloatBuffer();
1021                                    v.forEach((i, e) -> tb.put(e));
1022                                });
1023     }
1024 
1025     @Override
1026     @ForceInline
1027     public final void intoByteArray(byte[] a, int ix, Mask<Float> m) {
1028         Float128Vector oldVal = (Float128Vector) FloatVector.fromByteArray(SPECIES, a, ix);
1029         Float128Vector newVal = oldVal.blend(this, m);
1030         newVal.intoByteArray(a, ix);
1031     }
1032 
1033     @Override
1034     @ForceInline
1035     public void intoByteBuffer(ByteBuffer bb, int ix) {
1036         if (bb.order() != ByteOrder.nativeOrder()) {
1037             throw new IllegalArgumentException();
1038         }
1039         if (bb.isReadOnly()) {
1040             throw new ReadOnlyBufferException();
1041         }
1042         ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
1043         VectorIntrinsics.store(Float128Vector.class, float.class, LENGTH,
1044                                U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
1045                                this,
1046                                bb, ix,
1047                                (c, idx, v) -> {
1048                                    ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
1049                                    FloatBuffer tb = bbc.asFloatBuffer();
1050                                    v.forEach((i, e) -> tb.put(e));
1051                                });
1052     }
1053 
1054     @Override
1055     @ForceInline
1056     public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Float> m) {
1057         Float128Vector oldVal = (Float128Vector) FloatVector.fromByteBuffer(SPECIES, bb, ix);
1058         Float128Vector newVal = oldVal.blend(this, m);
1059         newVal.intoByteBuffer(bb, ix);
1060     }
1061 
1062     //
1063 
1064     @Override
1065     public String toString() {
1066         return Arrays.toString(getElements());
1067     }
1068 
1069     @Override
1070     public boolean equals(Object o) {
1071         if (this == o) return true;
1072         if (o == null || this.getClass() != o.getClass()) return false;
1073 
1074         Float128Vector that = (Float128Vector) o;
1075         return this.equal(that).allTrue();
1076     }
1077 
1078     @Override
1079     public int hashCode() {
1080         return Arrays.hashCode(vec);
1081     }
1082 
1083     // Binary test
1084 
1085     @Override
1086     Float128Mask bTest(Vector<Float> o, FBinTest f) {
1087         float[] vec1 = getElements();
1088         float[] vec2 = ((Float128Vector)o).getElements();
1089         boolean[] bits = new boolean[length()];
1090         for (int i = 0; i < length(); i++){
1091             bits[i] = f.apply(i, vec1[i], vec2[i]);
1092         }
1093         return new Float128Mask(bits);
1094     }
1095 
1096     // Comparisons
1097 
1098     @Override
1099     @ForceInline
1100     public Float128Mask equal(Vector<Float> o) {
1101         Objects.requireNonNull(o);
1102         Float128Vector v = (Float128Vector)o;
1103 
1104         return VectorIntrinsics.compare(
1105             BT_eq, Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1106             this, v,
1107             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1108     }
1109 
1110     @Override
1111     @ForceInline
1112     public Float128Mask notEqual(Vector<Float> o) {
1113         Objects.requireNonNull(o);
1114         Float128Vector v = (Float128Vector)o;
1115 
1116         return VectorIntrinsics.compare(
1117             BT_ne, Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1118             this, v,
1119             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1120     }
1121 
1122     @Override
1123     @ForceInline
1124     public Float128Mask lessThan(Vector<Float> o) {
1125         Objects.requireNonNull(o);
1126         Float128Vector v = (Float128Vector)o;
1127 
1128         return VectorIntrinsics.compare(
1129             BT_lt, Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1130             this, v,
1131             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1132     }
1133 
1134     @Override
1135     @ForceInline
1136     public Float128Mask lessThanEq(Vector<Float> o) {
1137         Objects.requireNonNull(o);
1138         Float128Vector v = (Float128Vector)o;
1139 
1140         return VectorIntrinsics.compare(
1141             BT_le, Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1142             this, v,
1143             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1144     }
1145 
1146     @Override
1147     @ForceInline
1148     public Float128Mask greaterThan(Vector<Float> o) {
1149         Objects.requireNonNull(o);
1150         Float128Vector v = (Float128Vector)o;
1151 
1152         return (Float128Mask) VectorIntrinsics.compare(
1153             BT_gt, Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1154             this, v,
1155             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1156     }
1157 
1158     @Override
1159     @ForceInline
1160     public Float128Mask greaterThanEq(Vector<Float> o) {
1161         Objects.requireNonNull(o);
1162         Float128Vector v = (Float128Vector)o;
1163 
1164         return VectorIntrinsics.compare(
1165             BT_ge, Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1166             this, v,
1167             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1168     }
1169 
1170     // Foreach
1171 
1172     @Override
1173     void forEach(FUnCon f) {
1174         float[] vec = getElements();
1175         for (int i = 0; i < length(); i++) {
1176             f.apply(i, vec[i]);
1177         }
1178     }
1179 
1180     @Override
1181     void forEach(Mask<Float> o, FUnCon f) {
1182         boolean[] mbits = ((Float128Mask)o).getBits();
1183         forEach((i, a) -> {
1184             if (mbits[i]) { f.apply(i, a); }
1185         });
1186     }
1187 
1188     Int128Vector toBits() {
1189         float[] vec = getElements();
1190         int[] res = new int[this.species().length()];
1191         for(int i = 0; i < this.species().length(); i++){
1192             res[i] = Float.floatToIntBits(vec[i]);
1193         }
1194         return new Int128Vector(res);
1195     }
1196 
1197 
1198     @Override
1199     public Float128Vector rotateEL(int j) {
1200         float[] vec = getElements();
1201         float[] res = new float[length()];
1202         for (int i = 0; i < length(); i++){
1203             res[(j + i) % length()] = vec[i];
1204         }
1205         return new Float128Vector(res);
1206     }
1207 
1208     @Override
1209     public Float128Vector rotateER(int j) {
1210         float[] vec = getElements();
1211         float[] res = new float[length()];
1212         for (int i = 0; i < length(); i++){
1213             int z = i - j;
1214             if(j < 0) {
1215                 res[length() + z] = vec[i];
1216             } else {
1217                 res[z] = vec[i];
1218             }
1219         }
1220         return new Float128Vector(res);
1221     }
1222 
1223     @Override
1224     public Float128Vector shiftEL(int j) {
1225         float[] vec = getElements();
1226         float[] res = new float[length()];
1227         for (int i = 0; i < length() - j; i++) {
1228             res[i] = vec[i + j];
1229         }
1230         return new Float128Vector(res);
1231     }
1232 
1233     @Override
1234     public Float128Vector shiftER(int j) {
1235         float[] vec = getElements();
1236         float[] res = new float[length()];
1237         for (int i = 0; i < length() - j; i++){
1238             res[i + j] = vec[i];
1239         }
1240         return new Float128Vector(res);
1241     }
1242 
1243     @Override
1244     @ForceInline
1245     public Float128Vector rearrange(Vector<Float> v,
1246                                   Shuffle<Float> s, Mask<Float> m) {
1247         return this.rearrange(s).blend(v.rearrange(s), m);
1248     }
1249 
1250     @Override
1251     @ForceInline
1252     public Float128Vector rearrange(Shuffle<Float> o1) {
1253         Objects.requireNonNull(o1);
1254         Float128Shuffle s =  (Float128Shuffle)o1;
1255 
1256         return VectorIntrinsics.rearrangeOp(
1257             Float128Vector.class, Float128Shuffle.class, float.class, LENGTH,
1258             this, s,
1259             (v1, s_) -> v1.uOp((i, a) -> {
1260                 int ei = s_.getElement(i);
1261                 return v1.get(ei);
1262             }));
1263     }
1264 
1265     @Override
1266     @ForceInline
1267     public Float128Vector blend(Vector<Float> o1, Mask<Float> o2) {
1268         Objects.requireNonNull(o1);
1269         Objects.requireNonNull(o2);
1270         Float128Vector v = (Float128Vector)o1;
1271         Float128Mask   m = (Float128Mask)o2;
1272 
1273         return VectorIntrinsics.blend(
1274             Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1275             this, v, m,
1276             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1277     }
1278 
1279     // Accessors
1280 
1281     @Override
1282     public float get(int i) {
1283         if (i < 0 || i >= LENGTH) {
1284             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1285         }
1286         int bits = (int) VectorIntrinsics.extract(
1287                                 Float128Vector.class, float.class, LENGTH,
1288                                 this, i,
1289                                 (vec, ix) -> {
1290                                     float[] vecarr = vec.getElements();
1291                                     return (long)Float.floatToIntBits(vecarr[ix]);
1292                                 });
1293         return Float.intBitsToFloat(bits);
1294     }
1295 
1296     @Override
1297     public Float128Vector with(int i, float e) {
1298         if (i < 0 || i >= LENGTH) {
1299             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1300         }
1301         return VectorIntrinsics.insert(
1302                                 Float128Vector.class, float.class, LENGTH,
1303                                 this, i, (long)Float.floatToIntBits(e),
1304                                 (v, ix, bits) -> {
1305                                     float[] res = v.getElements().clone();
1306                                     res[ix] = Float.intBitsToFloat((int)bits);
1307                                     return new Float128Vector(res);
1308                                 });
1309     }
1310 
1311     // Mask
1312 
1313     static final class Float128Mask extends AbstractMask<Float> {
1314         static final Float128Mask TRUE_MASK = new Float128Mask(true);
1315         static final Float128Mask FALSE_MASK = new Float128Mask(false);
1316 
1317         private final boolean[] bits; // Don't access directly, use getBits() instead.
1318 
1319         public Float128Mask(boolean[] bits) {
1320             this(bits, 0);
1321         }
1322 
1323         public Float128Mask(boolean[] bits, int offset) {
1324             boolean[] a = new boolean[species().length()];
1325             for (int i = 0; i < a.length; i++) {
1326                 a[i] = bits[offset + i];
1327             }
1328             this.bits = a;
1329         }
1330 
1331         public Float128Mask(boolean val) {
1332             boolean[] bits = new boolean[species().length()];
1333             Arrays.fill(bits, val);
1334             this.bits = bits;
1335         }
1336 
1337         boolean[] getBits() {
1338             return VectorIntrinsics.maybeRebox(this).bits;
1339         }
1340 
1341         @Override
1342         Float128Mask uOp(MUnOp f) {
1343             boolean[] res = new boolean[species().length()];
1344             boolean[] bits = getBits();
1345             for (int i = 0; i < species().length(); i++) {
1346                 res[i] = f.apply(i, bits[i]);
1347             }
1348             return new Float128Mask(res);
1349         }
1350 
1351         @Override
1352         Float128Mask bOp(Mask<Float> o, MBinOp f) {
1353             boolean[] res = new boolean[species().length()];
1354             boolean[] bits = getBits();
1355             boolean[] mbits = ((Float128Mask)o).getBits();
1356             for (int i = 0; i < species().length(); i++) {
1357                 res[i] = f.apply(i, bits[i], mbits[i]);
1358             }
1359             return new Float128Mask(res);
1360         }
1361 
1362         @Override
1363         public Float128Species species() {
1364             return SPECIES;
1365         }
1366 
1367         @Override
1368         public Float128Vector toVector() {
1369             float[] res = new float[species().length()];
1370             boolean[] bits = getBits();
1371             for (int i = 0; i < species().length(); i++) {
1372                 // -1 will result in the most significant bit being set in
1373                 // addition to some or all other bits
1374                 res[i] = (float) (bits[i] ? -1 : 0);
1375             }
1376             return new Float128Vector(res);
1377         }
1378 
1379         // Unary operations
1380 
1381         @Override
1382         @ForceInline
1383         public Float128Mask not() {
1384             return (Float128Mask) VectorIntrinsics.unaryOp(
1385                                              VECTOR_OP_NOT, Float128Mask.class, int.class, LENGTH,
1386                                              this,
1387                                              (m1) -> m1.uOp((i, a) -> !a));
1388         }
1389 
1390         // Binary operations
1391 
1392         @Override
1393         @ForceInline
1394         public Float128Mask and(Mask<Float> o) {
1395             Objects.requireNonNull(o);
1396             Float128Mask m = (Float128Mask)o;
1397             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Float128Mask.class, int.class, LENGTH,
1398                                              this, m,
1399                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1400         }
1401 
1402         @Override
1403         @ForceInline
1404         public Float128Mask or(Mask<Float> o) {
1405             Objects.requireNonNull(o);
1406             Float128Mask m = (Float128Mask)o;
1407             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Float128Mask.class, int.class, LENGTH,
1408                                              this, m,
1409                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1410         }
1411 
1412         // Reductions
1413 
1414         @Override
1415         @ForceInline
1416         public boolean anyTrue() {
1417             return VectorIntrinsics.test(BT_ne, Float128Mask.class, int.class, LENGTH,
1418                                          this, this,
1419                                          (m, __) -> anyTrueHelper(((Float128Mask)m).getBits()));
1420         }
1421 
1422         @Override
1423         @ForceInline
1424         public boolean allTrue() {
1425             return VectorIntrinsics.test(BT_overflow, Float128Mask.class, int.class, LENGTH,
1426                                          this, FloatVector.maskAllTrue(species()),
1427                                          (m, __) -> allTrueHelper(((Float128Mask)m).getBits()));
1428         }
1429     }
1430 
1431     // Shuffle
1432 
1433     static final class Float128Shuffle extends AbstractShuffle<Float> {
1434         Float128Shuffle(byte[] reorder) {
1435             super(reorder);
1436         }
1437 
1438         public Float128Shuffle(int[] reorder) {
1439             super(reorder);
1440         }
1441 
1442         public Float128Shuffle(int[] reorder, int i) {
1443             super(reorder, i);
1444         }
1445 
1446         public Float128Shuffle(IntUnaryOperator f) {
1447             super(f);
1448         }
1449 
1450         @Override
1451         public Float128Species species() {
1452             return SPECIES;
1453         }
1454 
1455         @Override
1456         public FloatVector toVector() {
1457             float[] va = new float[SPECIES.length()];
1458             for (int i = 0; i < va.length; i++) {
1459               va[i] = (float) getElement(i);
1460             }
1461             return FloatVector.fromArray(SPECIES, va, 0);
1462         }
1463 
1464         @Override
1465         public Float128Shuffle rearrange(Vector.Shuffle<Float> o) {
1466             Float128Shuffle s = (Float128Shuffle) o;
1467             byte[] r = new byte[reorder.length];
1468             for (int i = 0; i < reorder.length; i++) {
1469                 r[i] = reorder[s.reorder[i]];
1470             }
1471             return new Float128Shuffle(r);
1472         }
1473     }
1474 
1475     // Species
1476 
1477     @Override
1478     public Float128Species species() {
1479         return SPECIES;
1480     }
1481 
1482     static final class Float128Species extends FloatSpecies {
1483         static final int BIT_SIZE = Shape.S_128_BIT.bitSize();
1484 
1485         static final int LENGTH = BIT_SIZE / Float.SIZE;
1486 
1487         @Override
1488         public String toString() {
1489            StringBuilder sb = new StringBuilder("Shape[");
1490            sb.append(bitSize()).append(" bits, ");
1491            sb.append(length()).append(" ").append(float.class.getSimpleName()).append("s x ");
1492            sb.append(elementSize()).append(" bits");
1493            sb.append("]");
1494            return sb.toString();
1495         }
1496 
1497         @Override
1498         @ForceInline
1499         public int bitSize() {
1500             return BIT_SIZE;
1501         }
1502 
1503         @Override
1504         @ForceInline
1505         public int length() {
1506             return LENGTH;
1507         }
1508 
1509         @Override
1510         @ForceInline
1511         public Class<Float> elementType() {
1512             return float.class;
1513         }
1514 
1515         @Override
1516         @ForceInline
1517         public Class<?> boxType() {
1518             return Float128Vector.class;
1519         }
1520 
1521         @Override
1522         @ForceInline
1523         public Class<?> maskType() {
1524             return Float128Mask.class;
1525         }
1526 
1527         @Override
1528         @ForceInline
1529         public int elementSize() {
1530             return Float.SIZE;
1531         }
1532 
1533         @Override
1534         @ForceInline
1535         @SuppressWarnings("unchecked")
1536         Class<?> vectorType() {
1537             return Float128Vector.class;
1538         }
1539 
1540         @Override
1541         @ForceInline
1542         public Shape shape() {
1543             return Shape.S_128_BIT;
1544         }
1545 
1546        @Override
1547        IntVector.IntSpecies indexSpecies() {
1548           return INDEX_SPEC;
1549        }
1550 
1551         @Override
1552         Float128Vector op(FOp f) {
1553             float[] res = new float[length()];
1554             for (int i = 0; i < length(); i++) {
1555                 res[i] = f.apply(i);
1556             }
1557             return new Float128Vector(res);
1558         }
1559 
1560         @Override
1561         Float128Vector op(Mask<Float> o, FOp f) {
1562             float[] res = new float[length()];
1563             boolean[] mbits = ((Float128Mask)o).getBits();
1564             for (int i = 0; i < length(); i++) {
1565                 if (mbits[i]) {
1566                     res[i] = f.apply(i);
1567                 }
1568             }
1569             return new Float128Vector(res);
1570         }
1571 
1572         @Override
1573         Float128Mask opm(FOpm f) {
1574             boolean[] res = new boolean[length()];
1575             for (int i = 0; i < length(); i++) {
1576                 res[i] = (boolean)f.apply(i);
1577             }
1578             return new Float128Mask(res);
1579         }
1580 
1581         // Factories
1582 
1583         @Override
1584         @ForceInline
1585         public Float128Vector zero() {
1586             return VectorIntrinsics.broadcastCoerced(Float128Vector.class, float.class, LENGTH,
1587                                                      Float.floatToIntBits(0.0f), SPECIES, 
1588                                                      ((bits, s) -> ((Float128Species)s).op(i -> Float.intBitsToFloat((int)bits))));
1589         }
1590 
1591         @Override
1592         @ForceInline
1593         public Float128Vector broadcast(float e) {
1594             return VectorIntrinsics.broadcastCoerced(
1595                 Float128Vector.class, float.class, LENGTH,
1596                 Float.floatToIntBits(e), SPECIES,
1597                 ((bits, s) -> ((Float128Species)s).op(i -> Float.intBitsToFloat((int)bits))));
1598         }
1599 
1600         @Override
1601         @ForceInline
1602         public Float128Vector scalars(float... es) {
1603             Objects.requireNonNull(es);
1604             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1605             return VectorIntrinsics.load(Float128Vector.class, float.class, LENGTH,
1606                                          es, Unsafe.ARRAY_FLOAT_BASE_OFFSET,
1607                                          es, ix, SPECIES,
1608                                          (c, idx, s) -> ((Float128Species)s).op(n -> c[idx + n]));
1609         }
1610 
1611         @Override
1612         @ForceInline
1613         public <E> Float128Mask cast(Mask<E> m) {
1614             if (m.length() != LENGTH)
1615                 throw new IllegalArgumentException("Mask length this species length differ");
1616             return new Float128Mask(m.toArray());
1617         }
1618 
1619         @Override
1620         @ForceInline
1621         public <E> Float128Shuffle cast(Shuffle<E> s) {
1622             if (s.length() != LENGTH)
1623                 throw new IllegalArgumentException("Shuffle length this species length differ");
1624             return new Float128Shuffle(s.toArray());
1625         }
1626     }
1627 }