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