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