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