1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have
  23  * questions.
  24  */
  25 package jdk.incubator.vector;
  26 
  27 import java.nio.ByteBuffer;
  28 import java.nio.ByteOrder;
  29 import java.nio.FloatBuffer;
  30 import java.nio.ReadOnlyBufferException;
  31 import java.util.Arrays;
  32 import java.util.Objects;
  33 import java.util.function.IntUnaryOperator;
  34 
  35 import jdk.internal.misc.Unsafe;
  36 import jdk.internal.vm.annotation.ForceInline;
  37 import static jdk.incubator.vector.VectorIntrinsics.*;
  38 
  39 @SuppressWarnings("cast")
  40 final class Float256Vector extends FloatVector {
  41     private static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_256;
  42 
  43     static final Float256Vector ZERO = new Float256Vector();
  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 float[] vec; // Don't access directly, use getElements() instead.
  56 
  57     private float[] getElements() {
  58         return VectorIntrinsics.maybeRebox(this).vec;
  59     }
  60 
  61     Float256Vector() {
  62         vec = new float[SPECIES.length()];
  63     }
  64 
  65     Float256Vector(float[] v) {
  66         vec = v;
  67     }
  68 
  69     @Override
  70     public int length() { return LENGTH; }
  71 
  72     // Unary operator
  73 
  74     @Override
  75     Float256Vector uOp(FUnOp f) {
  76         float[] vec = getElements();
  77         float[] res = new float[length()];
  78         for (int i = 0; i < length(); i++) {
  79             res[i] = f.apply(i, vec[i]);
  80         }
  81         return new Float256Vector(res);
  82     }
  83 
  84     @Override
  85     Float256Vector uOp(VectorMask<Float> o, FUnOp f) {
  86         float[] vec = getElements();
  87         float[] res = new float[length()];
  88         boolean[] mbits = ((Float256Mask)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 Float256Vector(res);
  93     }
  94 
  95     // Binary operator
  96 
  97     @Override
  98     Float256Vector bOp(Vector<Float> o, FBinOp f) {
  99         float[] res = new float[length()];
 100         float[] vec1 = this.getElements();
 101         float[] vec2 = ((Float256Vector)o).getElements();
 102         for (int i = 0; i < length(); i++) {
 103             res[i] = f.apply(i, vec1[i], vec2[i]);
 104         }
 105         return new Float256Vector(res);
 106     }
 107 
 108     @Override
 109     Float256Vector bOp(Vector<Float> o1, VectorMask<Float> o2, FBinOp f) {
 110         float[] res = new float[length()];
 111         float[] vec1 = this.getElements();
 112         float[] vec2 = ((Float256Vector)o1).getElements();
 113         boolean[] mbits = ((Float256Mask)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 Float256Vector(res);
 118     }
 119 
 120     // Trinary operator
 121 
 122     @Override
 123     Float256Vector tOp(Vector<Float> o1, Vector<Float> o2, FTriOp f) {
 124         float[] res = new float[length()];
 125         float[] vec1 = this.getElements();
 126         float[] vec2 = ((Float256Vector)o1).getElements();
 127         float[] vec3 = ((Float256Vector)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 Float256Vector(res);
 132     }
 133 
 134     @Override
 135     Float256Vector tOp(Vector<Float> o1, Vector<Float> o2, VectorMask<Float> o3, FTriOp f) {
 136         float[] res = new float[length()];
 137         float[] vec1 = getElements();
 138         float[] vec2 = ((Float256Vector)o1).getElements();
 139         float[] vec3 = ((Float256Vector)o2).getElements();
 140         boolean[] mbits = ((Float256Mask)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 Float256Vector(res);
 145     }
 146 
 147     @Override
 148     float rOp(float v, FBinOp f) {
 149         float[] 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             Float256Vector.class,
 165             float.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(float.class)) {
 227             return (Vector<F>) reshape((VectorSpecies<Float>)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                 Float256Vector.class,
 244                 float.class, LENGTH,
 245                 Byte256Vector.class,
 246                 byte.class, Byte256Vector.LENGTH,
 247                 this, s,
 248                 (species, vector) -> vector.defaultReinterpret(species)
 249             );
 250         } else if (stype == short.class) {
 251             return VectorIntrinsics.reinterpret(
 252                 Float256Vector.class,
 253                 float.class, LENGTH,
 254                 Short256Vector.class,
 255                 short.class, Short256Vector.LENGTH,
 256                 this, s,
 257                 (species, vector) -> vector.defaultReinterpret(species)
 258             );
 259         } else if (stype == int.class) {
 260             return VectorIntrinsics.reinterpret(
 261                 Float256Vector.class,
 262                 float.class, LENGTH,
 263                 Int256Vector.class,
 264                 int.class, Int256Vector.LENGTH,
 265                 this, s,
 266                 (species, vector) -> vector.defaultReinterpret(species)
 267             );
 268         } else if (stype == long.class) {
 269             return VectorIntrinsics.reinterpret(
 270                 Float256Vector.class,
 271                 float.class, LENGTH,
 272                 Long256Vector.class,
 273                 long.class, Long256Vector.LENGTH,
 274                 this, s,
 275                 (species, vector) -> vector.defaultReinterpret(species)
 276             );
 277         } else if (stype == float.class) {
 278             return VectorIntrinsics.reinterpret(
 279                 Float256Vector.class,
 280                 float.class, LENGTH,
 281                 Float256Vector.class,
 282                 float.class, Float256Vector.LENGTH,
 283                 this, s,
 284                 (species, vector) -> vector.defaultReinterpret(species)
 285             );
 286         } else if (stype == double.class) {
 287             return VectorIntrinsics.reinterpret(
 288                 Float256Vector.class,
 289                 float.class, LENGTH,
 290                 Double256Vector.class,
 291                 double.class, Double256Vector.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 FloatVector reshape(VectorSpecies<Float> s) {
 303         Objects.requireNonNull(s);
 304         if (s.bitSize() == 64 && (s.vectorType() == Float64Vector.class)) {
 305             return VectorIntrinsics.reinterpret(
 306                 Float256Vector.class,
 307                 float.class, LENGTH,
 308                 Float64Vector.class,
 309                 float.class, Float64Vector.LENGTH,
 310                 this, s,
 311                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 312             );
 313         } else if (s.bitSize() == 128 && (s.vectorType() == Float128Vector.class)) {
 314             return VectorIntrinsics.reinterpret(
 315                 Float256Vector.class,
 316                 float.class, LENGTH,
 317                 Float128Vector.class,
 318                 float.class, Float128Vector.LENGTH,
 319                 this, s,
 320                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 321             );
 322         } else if (s.bitSize() == 256 && (s.vectorType() == Float256Vector.class)) {
 323             return VectorIntrinsics.reinterpret(
 324                 Float256Vector.class,
 325                 float.class, LENGTH,
 326                 Float256Vector.class,
 327                 float.class, Float256Vector.LENGTH,
 328                 this, s,
 329                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 330             );
 331         } else if (s.bitSize() == 512 && (s.vectorType() == Float512Vector.class)) {
 332             return VectorIntrinsics.reinterpret(
 333                 Float256Vector.class,
 334                 float.class, LENGTH,
 335                 Float512Vector.class,
 336                 float.class, Float512Vector.LENGTH,
 337                 this, s,
 338                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 339             );
 340         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 341                 && (s.bitSize() % 128 == 0) && (s.vectorType() == FloatMaxVector.class)) {
 342             return VectorIntrinsics.reinterpret(
 343                 Float256Vector.class,
 344                 float.class, LENGTH,
 345                 FloatMaxVector.class,
 346                 float.class, FloatMaxVector.LENGTH,
 347                 this, s,
 348                 (species, vector) -> (FloatVector) 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 FloatVector add(float o) {
 360         return add((Float256Vector)FloatVector.broadcast(SPECIES, o));
 361     }
 362 
 363     @Override
 364     @ForceInline
 365     public FloatVector add(float o, VectorMask<Float> m) {
 366         return add((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 367     }
 368 
 369     @Override
 370     @ForceInline
 371     public FloatVector sub(float o) {
 372         return sub((Float256Vector)FloatVector.broadcast(SPECIES, o));
 373     }
 374 
 375     @Override
 376     @ForceInline
 377     public FloatVector sub(float o, VectorMask<Float> m) {
 378         return sub((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 379     }
 380 
 381     @Override
 382     @ForceInline
 383     public FloatVector mul(float o) {
 384         return mul((Float256Vector)FloatVector.broadcast(SPECIES, o));
 385     }
 386 
 387     @Override
 388     @ForceInline
 389     public FloatVector mul(float o, VectorMask<Float> m) {
 390         return mul((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 391     }
 392 
 393     @Override
 394     @ForceInline
 395     public FloatVector min(float o) {
 396         return min((Float256Vector)FloatVector.broadcast(SPECIES, o));
 397     }
 398 
 399     @Override
 400     @ForceInline
 401     public FloatVector max(float o) {
 402         return max((Float256Vector)FloatVector.broadcast(SPECIES, o));
 403     }
 404 
 405     @Override
 406     @ForceInline
 407     public VectorMask<Float> equal(float o) {
 408         return equal((Float256Vector)FloatVector.broadcast(SPECIES, o));
 409     }
 410 
 411     @Override
 412     @ForceInline
 413     public VectorMask<Float> notEqual(float o) {
 414         return notEqual((Float256Vector)FloatVector.broadcast(SPECIES, o));
 415     }
 416 
 417     @Override
 418     @ForceInline
 419     public VectorMask<Float> lessThan(float o) {
 420         return lessThan((Float256Vector)FloatVector.broadcast(SPECIES, o));
 421     }
 422 
 423     @Override
 424     @ForceInline
 425     public VectorMask<Float> lessThanEq(float o) {
 426         return lessThanEq((Float256Vector)FloatVector.broadcast(SPECIES, o));
 427     }
 428 
 429     @Override
 430     @ForceInline
 431     public VectorMask<Float> greaterThan(float o) {
 432         return greaterThan((Float256Vector)FloatVector.broadcast(SPECIES, o));
 433     }
 434 
 435     @Override
 436     @ForceInline
 437     public VectorMask<Float> greaterThanEq(float o) {
 438         return greaterThanEq((Float256Vector)FloatVector.broadcast(SPECIES, o));
 439     }
 440 
 441     @Override
 442     @ForceInline
 443     public FloatVector blend(float o, VectorMask<Float> m) {
 444         return blend((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 445     }
 446 
 447     @Override
 448     @ForceInline
 449     public FloatVector div(float o) {
 450         return div((Float256Vector)FloatVector.broadcast(SPECIES, o));
 451     }
 452 
 453     @Override
 454     @ForceInline
 455     public FloatVector div(float o, VectorMask<Float> m) {
 456         return div((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 457     }
 458 
 459     @Override
 460     @ForceInline
 461     public Float256Vector div(Vector<Float> v, VectorMask<Float> m) {
 462         return blend(div(v), m);
 463     }
 464 
 465     @Override
 466     @ForceInline
 467     public FloatVector atan2(float o) {
 468         return atan2((Float256Vector)FloatVector.broadcast(SPECIES, o));
 469     }
 470 
 471     @Override
 472     @ForceInline
 473     public FloatVector atan2(float o, VectorMask<Float> m) {
 474         return atan2((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 475     }
 476 
 477     @Override
 478     @ForceInline
 479     public FloatVector pow(float o) {
 480         return pow((Float256Vector)FloatVector.broadcast(SPECIES, o));
 481     }
 482 
 483     @Override
 484     @ForceInline
 485     public FloatVector pow(float o, VectorMask<Float> m) {
 486         return pow((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 487     }
 488 
 489     @Override
 490     @ForceInline
 491     public FloatVector fma(float o1, float o2) {
 492         return fma((Float256Vector)FloatVector.broadcast(SPECIES, o1), (Float256Vector)FloatVector.broadcast(SPECIES, o2));
 493     }
 494 
 495     @Override
 496     @ForceInline
 497     public FloatVector fma(float o1, float o2, VectorMask<Float> m) {
 498         return fma((Float256Vector)FloatVector.broadcast(SPECIES, o1), (Float256Vector)FloatVector.broadcast(SPECIES, o2), m);
 499     }
 500 
 501     @Override
 502     @ForceInline
 503     public FloatVector hypot(float o) {
 504         return hypot((Float256Vector)FloatVector.broadcast(SPECIES, o));
 505     }
 506 
 507     @Override
 508     @ForceInline
 509     public FloatVector hypot(float o, VectorMask<Float> m) {
 510         return hypot((Float256Vector)FloatVector.broadcast(SPECIES, o), m);
 511     }
 512 
 513 
 514     // Unary operations
 515 
 516     @ForceInline
 517     @Override
 518     public Float256Vector neg(VectorMask<Float> m) {
 519         return blend(neg(), m);
 520     }
 521 
 522     @Override
 523     @ForceInline
 524     public Float256Vector abs() {
 525         return VectorIntrinsics.unaryOp(
 526             VECTOR_OP_ABS, Float256Vector.class, float.class, LENGTH,
 527             this,
 528             v1 -> v1.uOp((i, a) -> (float) Math.abs(a)));
 529     }
 530 
 531     @ForceInline
 532     @Override
 533     public Float256Vector abs(VectorMask<Float> m) {
 534         return blend(abs(), m);
 535     }
 536 
 537     @Override
 538     @ForceInline
 539     public Float256Vector neg() {
 540         return VectorIntrinsics.unaryOp(
 541             VECTOR_OP_NEG, Float256Vector.class, float.class, LENGTH,
 542             this,
 543             v1 -> v1.uOp((i, a) -> (float) -a));
 544     }
 545 
 546     @Override
 547     @ForceInline
 548     public Float256Vector div(Vector<Float> o) {
 549         Objects.requireNonNull(o);
 550         Float256Vector v = (Float256Vector)o;
 551         return VectorIntrinsics.binaryOp(
 552             VECTOR_OP_DIV, Float256Vector.class, float.class, LENGTH,
 553             this, v,
 554             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (float)(a / b)));
 555     }
 556 
 557     @Override
 558     @ForceInline
 559     public Float256Vector sqrt() {
 560         return VectorIntrinsics.unaryOp(
 561             VECTOR_OP_SQRT, Float256Vector.class, float.class, LENGTH,
 562             this,
 563             v1 -> v1.uOp((i, a) -> (float) Math.sqrt((double) a)));
 564     }
 565 
 566     @Override
 567     @ForceInline
 568     public Float256Vector exp() {
 569         return (Float256Vector) VectorIntrinsics.unaryOp(
 570             VECTOR_OP_EXP, Float256Vector.class, float.class, LENGTH,
 571             this,
 572             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.exp((double) a)));
 573     }
 574 
 575     @Override
 576     @ForceInline
 577     public Float256Vector log1p() {
 578         return (Float256Vector) VectorIntrinsics.unaryOp(
 579             VECTOR_OP_LOG1P, Float256Vector.class, float.class, LENGTH,
 580             this,
 581             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.log1p((double) a)));
 582     }
 583 
 584     @Override
 585     @ForceInline
 586     public Float256Vector log() {
 587         return (Float256Vector) VectorIntrinsics.unaryOp(
 588             VECTOR_OP_LOG, Float256Vector.class, float.class, LENGTH,
 589             this,
 590             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.log((double) a)));
 591     }
 592 
 593     @Override
 594     @ForceInline
 595     public Float256Vector log10() {
 596         return (Float256Vector) VectorIntrinsics.unaryOp(
 597             VECTOR_OP_LOG10, Float256Vector.class, float.class, LENGTH,
 598             this,
 599             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.log10((double) a)));
 600     }
 601 
 602     @Override
 603     @ForceInline
 604     public Float256Vector expm1() {
 605         return (Float256Vector) VectorIntrinsics.unaryOp(
 606             VECTOR_OP_EXPM1, Float256Vector.class, float.class, LENGTH,
 607             this,
 608             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.expm1((double) a)));
 609     }
 610 
 611     @Override
 612     @ForceInline
 613     public Float256Vector cbrt() {
 614         return (Float256Vector) VectorIntrinsics.unaryOp(
 615             VECTOR_OP_CBRT, Float256Vector.class, float.class, LENGTH,
 616             this,
 617             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.cbrt((double) a)));
 618     }
 619 
 620     @Override
 621     @ForceInline
 622     public Float256Vector sin() {
 623         return (Float256Vector) VectorIntrinsics.unaryOp(
 624             VECTOR_OP_SIN, Float256Vector.class, float.class, LENGTH,
 625             this,
 626             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.sin((double) a)));
 627     }
 628 
 629     @Override
 630     @ForceInline
 631     public Float256Vector cos() {
 632         return (Float256Vector) VectorIntrinsics.unaryOp(
 633             VECTOR_OP_COS, Float256Vector.class, float.class, LENGTH,
 634             this,
 635             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.cos((double) a)));
 636     }
 637 
 638     @Override
 639     @ForceInline
 640     public Float256Vector tan() {
 641         return (Float256Vector) VectorIntrinsics.unaryOp(
 642             VECTOR_OP_TAN, Float256Vector.class, float.class, LENGTH,
 643             this,
 644             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.tan((double) a)));
 645     }
 646 
 647     @Override
 648     @ForceInline
 649     public Float256Vector asin() {
 650         return (Float256Vector) VectorIntrinsics.unaryOp(
 651             VECTOR_OP_ASIN, Float256Vector.class, float.class, LENGTH,
 652             this,
 653             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.asin((double) a)));
 654     }
 655 
 656     @Override
 657     @ForceInline
 658     public Float256Vector acos() {
 659         return (Float256Vector) VectorIntrinsics.unaryOp(
 660             VECTOR_OP_ACOS, Float256Vector.class, float.class, LENGTH,
 661             this,
 662             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.acos((double) a)));
 663     }
 664 
 665     @Override
 666     @ForceInline
 667     public Float256Vector atan() {
 668         return (Float256Vector) VectorIntrinsics.unaryOp(
 669             VECTOR_OP_ATAN, Float256Vector.class, float.class, LENGTH,
 670             this,
 671             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.atan((double) a)));
 672     }
 673 
 674     @Override
 675     @ForceInline
 676     public Float256Vector sinh() {
 677         return (Float256Vector) VectorIntrinsics.unaryOp(
 678             VECTOR_OP_SINH, Float256Vector.class, float.class, LENGTH,
 679             this,
 680             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.sinh((double) a)));
 681     }
 682 
 683     @Override
 684     @ForceInline
 685     public Float256Vector cosh() {
 686         return (Float256Vector) VectorIntrinsics.unaryOp(
 687             VECTOR_OP_COSH, Float256Vector.class, float.class, LENGTH,
 688             this,
 689             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.cosh((double) a)));
 690     }
 691 
 692     @Override
 693     @ForceInline
 694     public Float256Vector tanh() {
 695         return (Float256Vector) VectorIntrinsics.unaryOp(
 696             VECTOR_OP_TANH, Float256Vector.class, float.class, LENGTH,
 697             this,
 698             v1 -> ((Float256Vector)v1).uOp((i, a) -> (float) Math.tanh((double) a)));
 699     }
 700 
 701     @Override
 702     @ForceInline
 703     public Float256Vector pow(Vector<Float> o) {
 704         Objects.requireNonNull(o);
 705         Float256Vector v = (Float256Vector)o;
 706         return (Float256Vector) VectorIntrinsics.binaryOp(
 707             VECTOR_OP_POW, Float256Vector.class, float.class, LENGTH,
 708             this, v,
 709             (v1, v2) -> ((Float256Vector)v1).bOp(v2, (i, a, b) -> (float)(Math.pow(a,b))));
 710     }
 711 
 712     @Override
 713     @ForceInline
 714     public Float256Vector hypot(Vector<Float> o) {
 715         Objects.requireNonNull(o);
 716         Float256Vector v = (Float256Vector)o;
 717         return (Float256Vector) VectorIntrinsics.binaryOp(
 718             VECTOR_OP_HYPOT, Float256Vector.class, float.class, LENGTH,
 719             this, v,
 720             (v1, v2) -> ((Float256Vector)v1).bOp(v2, (i, a, b) -> (float)(Math.hypot(a,b))));
 721     }
 722 
 723     @Override
 724     @ForceInline
 725     public Float256Vector atan2(Vector<Float> o) {
 726         Objects.requireNonNull(o);
 727         Float256Vector v = (Float256Vector)o;
 728         return (Float256Vector) VectorIntrinsics.binaryOp(
 729             VECTOR_OP_ATAN2, Float256Vector.class, float.class, LENGTH,
 730             this, v,
 731             (v1, v2) -> ((Float256Vector)v1).bOp(v2, (i, a, b) -> (float)(Math.atan2(a,b))));
 732     }
 733 
 734 
 735     // Binary operations
 736 
 737     @Override
 738     @ForceInline
 739     public Float256Vector add(Vector<Float> o) {
 740         Objects.requireNonNull(o);
 741         Float256Vector v = (Float256Vector)o;
 742         return VectorIntrinsics.binaryOp(
 743             VECTOR_OP_ADD, Float256Vector.class, float.class, LENGTH,
 744             this, v,
 745             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (float)(a + b)));
 746     }
 747 
 748     @Override
 749     @ForceInline
 750     public Float256Vector add(Vector<Float> v, VectorMask<Float> m) {
 751         return blend(add(v), m);
 752     }
 753 
 754     @Override
 755     @ForceInline
 756     public Float256Vector sub(Vector<Float> o) {
 757         Objects.requireNonNull(o);
 758         Float256Vector v = (Float256Vector)o;
 759         return VectorIntrinsics.binaryOp(
 760             VECTOR_OP_SUB, Float256Vector.class, float.class, LENGTH,
 761             this, v,
 762             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (float)(a - b)));
 763     }
 764 
 765     @Override
 766     @ForceInline
 767     public Float256Vector sub(Vector<Float> v, VectorMask<Float> m) {
 768         return blend(sub(v), m);
 769     }
 770 
 771     @Override
 772     @ForceInline
 773     public Float256Vector mul(Vector<Float> o) {
 774         Objects.requireNonNull(o);
 775         Float256Vector v = (Float256Vector)o;
 776         return VectorIntrinsics.binaryOp(
 777             VECTOR_OP_MUL, Float256Vector.class, float.class, LENGTH,
 778             this, v,
 779             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (float)(a * b)));
 780     }
 781 
 782     @Override
 783     @ForceInline
 784     public Float256Vector mul(Vector<Float> v, VectorMask<Float> m) {
 785         return blend(mul(v), m);
 786     }
 787 
 788     @Override
 789     @ForceInline
 790     public Float256Vector min(Vector<Float> o) {
 791         Objects.requireNonNull(o);
 792         Float256Vector v = (Float256Vector)o;
 793         return (Float256Vector) VectorIntrinsics.binaryOp(
 794             VECTOR_OP_MIN, Float256Vector.class, float.class, LENGTH,
 795             this, v,
 796             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (float) Math.min(a, b)));
 797     }
 798 
 799     @Override
 800     @ForceInline
 801     public Float256Vector min(Vector<Float> v, VectorMask<Float> m) {
 802         return blend(min(v), m);
 803     }
 804 
 805     @Override
 806     @ForceInline
 807     public Float256Vector max(Vector<Float> o) {
 808         Objects.requireNonNull(o);
 809         Float256Vector v = (Float256Vector)o;
 810         return VectorIntrinsics.binaryOp(
 811             VECTOR_OP_MAX, Float256Vector.class, float.class, LENGTH,
 812             this, v,
 813             (v1, v2) -> v1.bOp(v2, (i, a, b) -> (float) Math.max(a, b)));
 814         }
 815 
 816     @Override
 817     @ForceInline
 818     public Float256Vector max(Vector<Float> v, VectorMask<Float> m) {
 819         return blend(max(v), m);
 820     }
 821 
 822 
 823     // Ternary operations
 824 
 825     @Override
 826     @ForceInline
 827     public Float256Vector fma(Vector<Float> o1, Vector<Float> o2) {
 828         Objects.requireNonNull(o1);
 829         Objects.requireNonNull(o2);
 830         Float256Vector v1 = (Float256Vector)o1;
 831         Float256Vector v2 = (Float256Vector)o2;
 832         return VectorIntrinsics.ternaryOp(
 833             VECTOR_OP_FMA, Float256Vector.class, float.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 float addLanes() {
 843         int bits = (int) VectorIntrinsics.reductionCoerced(
 844                                 VECTOR_OP_ADD, Float256Vector.class, float.class, LENGTH,
 845                                 this,
 846                                 v -> {
 847                                     float r = v.rOp((float) 0, (i, a, b) -> (float) (a + b));
 848                                     return (long)Float.floatToIntBits(r);
 849                                 });
 850         return Float.intBitsToFloat(bits);
 851     }
 852 
 853     @Override
 854     @ForceInline
 855     public float mulLanes() {
 856         int bits = (int) VectorIntrinsics.reductionCoerced(
 857                                 VECTOR_OP_MUL, Float256Vector.class, float.class, LENGTH,
 858                                 this,
 859                                 v -> {
 860                                     float r = v.rOp((float) 1, (i, a, b) -> (float) (a * b));
 861                                     return (long)Float.floatToIntBits(r);
 862                                 });
 863         return Float.intBitsToFloat(bits);
 864     }
 865 
 866     @Override
 867     @ForceInline
 868     public float minLanes() {
 869         int bits = (int) VectorIntrinsics.reductionCoerced(
 870                                 VECTOR_OP_MIN, Float256Vector.class, float.class, LENGTH,
 871                                 this,
 872                                 v -> {
 873                                     float r = v.rOp(Float.POSITIVE_INFINITY , (i, a, b) -> (float) Math.min(a, b));
 874                                     return (long)Float.floatToIntBits(r);
 875                                 });
 876         return Float.intBitsToFloat(bits);
 877     }
 878 
 879     @Override
 880     @ForceInline
 881     public float maxLanes() {
 882         int bits = (int) VectorIntrinsics.reductionCoerced(
 883                                 VECTOR_OP_MAX, Float256Vector.class, float.class, LENGTH,
 884                                 this,
 885                                 v -> {
 886                                     float r = v.rOp(Float.NEGATIVE_INFINITY, (i, a, b) -> (float) Math.max(a, b));
 887                                     return (long)Float.floatToIntBits(r);
 888                                 });
 889         return Float.intBitsToFloat(bits);
 890     }
 891 
 892 
 893     @Override
 894     @ForceInline
 895     public float addLanes(VectorMask<Float> m) {
 896         return FloatVector.broadcast(SPECIES, (float) 0).blend(this, m).addLanes();
 897     }
 898 
 899 
 900     @Override
 901     @ForceInline
 902     public float mulLanes(VectorMask<Float> m) {
 903         return FloatVector.broadcast(SPECIES, (float) 1).blend(this, m).mulLanes();
 904     }
 905 
 906     @Override
 907     @ForceInline
 908     public float minLanes(VectorMask<Float> m) {
 909         return FloatVector.broadcast(SPECIES, Float.MAX_VALUE).blend(this, m).minLanes();
 910     }
 911 
 912     @Override
 913     @ForceInline
 914     public float maxLanes(VectorMask<Float> m) {
 915         return FloatVector.broadcast(SPECIES, Float.MIN_VALUE).blend(this, m).maxLanes();
 916     }
 917 
 918     @Override
 919     @ForceInline
 920     public VectorShuffle<Float> toShuffle() {
 921         float[] 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_FLOAT_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(float[] a, int ix) {
 937         Objects.requireNonNull(a);
 938         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 939         VectorIntrinsics.store(Float256Vector.class, float.class, LENGTH,
 940                                a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_FLOAT_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(float[] a, int ax, VectorMask<Float> m) {
 949         FloatVector oldVal = FloatVector.fromArray(SPECIES, a, ax);
 950         FloatVector newVal = oldVal.blend(this, m);
 951         newVal.intoArray(a, ax);
 952     }
 953     @Override
 954     @ForceInline
 955     public void intoArray(float[] 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(Float256Vector.class, float.class, LENGTH, Int256Vector.class,
 965                                a, Unsafe.ARRAY_FLOAT_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(float[] a, int ax, VectorMask<Float> m, int[] b, int iy) {
 974          // @@@ This can result in out of bounds errors for unset mask lanes
 975          FloatVector oldVal = FloatVector.fromArray(SPECIES, a, ax, b, iy);
 976          FloatVector 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(Float256Vector.class, float.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                                    FloatBuffer tb = bbc.asFloatBuffer();
 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<Float> m) {
 999         Float256Vector oldVal = (Float256Vector) FloatVector.fromByteArray(SPECIES, a, ix);
1000         Float256Vector 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(Float256Vector.class, float.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                                    FloatBuffer tb = bbc.asFloatBuffer();
1021                                    v.forEach((i, e) -> tb.put(e));
1022                                });
1023     }
1024 
1025     @Override
1026     @ForceInline
1027     public void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<Float> m) {
1028         Float256Vector oldVal = (Float256Vector) FloatVector.fromByteBuffer(SPECIES, bb, ix);
1029         Float256Vector 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         Float256Vector that = (Float256Vector) 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     Float256Mask bTest(Vector<Float> o, FBinTest f) {
1058         float[] vec1 = getElements();
1059         float[] vec2 = ((Float256Vector)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 Float256Mask(bits);
1065     }
1066 
1067     // Comparisons
1068 
1069     @Override
1070     @ForceInline
1071     public Float256Mask equal(Vector<Float> o) {
1072         Objects.requireNonNull(o);
1073         Float256Vector v = (Float256Vector)o;
1074 
1075         return VectorIntrinsics.compare(
1076             BT_eq, Float256Vector.class, Float256Mask.class, float.class, LENGTH,
1077             this, v,
1078             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
1079     }
1080 
1081     @Override
1082     @ForceInline
1083     public Float256Mask notEqual(Vector<Float> o) {
1084         Objects.requireNonNull(o);
1085         Float256Vector v = (Float256Vector)o;
1086 
1087         return VectorIntrinsics.compare(
1088             BT_ne, Float256Vector.class, Float256Mask.class, float.class, LENGTH,
1089             this, v,
1090             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
1091     }
1092 
1093     @Override
1094     @ForceInline
1095     public Float256Mask lessThan(Vector<Float> o) {
1096         Objects.requireNonNull(o);
1097         Float256Vector v = (Float256Vector)o;
1098 
1099         return VectorIntrinsics.compare(
1100             BT_lt, Float256Vector.class, Float256Mask.class, float.class, LENGTH,
1101             this, v,
1102             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
1103     }
1104 
1105     @Override
1106     @ForceInline
1107     public Float256Mask lessThanEq(Vector<Float> o) {
1108         Objects.requireNonNull(o);
1109         Float256Vector v = (Float256Vector)o;
1110 
1111         return VectorIntrinsics.compare(
1112             BT_le, Float256Vector.class, Float256Mask.class, float.class, LENGTH,
1113             this, v,
1114             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
1115     }
1116 
1117     @Override
1118     @ForceInline
1119     public Float256Mask greaterThan(Vector<Float> o) {
1120         Objects.requireNonNull(o);
1121         Float256Vector v = (Float256Vector)o;
1122 
1123         return (Float256Mask) VectorIntrinsics.compare(
1124             BT_gt, Float256Vector.class, Float256Mask.class, float.class, LENGTH,
1125             this, v,
1126             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
1127     }
1128 
1129     @Override
1130     @ForceInline
1131     public Float256Mask greaterThanEq(Vector<Float> o) {
1132         Objects.requireNonNull(o);
1133         Float256Vector v = (Float256Vector)o;
1134 
1135         return VectorIntrinsics.compare(
1136             BT_ge, Float256Vector.class, Float256Mask.class, float.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         float[] 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<Float> o, FUnCon f) {
1153         boolean[] mbits = ((Float256Mask)o).getBits();
1154         forEach((i, a) -> {
1155             if (mbits[i]) { f.apply(i, a); }
1156         });
1157     }
1158 
1159     Int256Vector toBits() {
1160         float[] vec = getElements();
1161         int[] res = new int[this.species().length()];
1162         for(int i = 0; i < this.species().length(); i++){
1163             res[i] = Float.floatToIntBits(vec[i]);
1164         }
1165         return new Int256Vector(res);
1166     }
1167 
1168 
1169     @Override
1170     public Float256Vector rotateLanesLeft(int j) {
1171         float[] vec = getElements();
1172         float[] res = new float[length()];
1173         for (int i = 0; i < length(); i++){
1174             res[(j + i) % length()] = vec[i];
1175         }
1176         return new Float256Vector(res);
1177     }
1178 
1179     @Override
1180     public Float256Vector rotateLanesRight(int j) {
1181         float[] vec = getElements();
1182         float[] res = new float[length()];
1183         for (int i = 0; i < length(); i++){
1184             int z = i - j;
1185             if(j < 0) {
1186                 res[length() + z] = vec[i];
1187             } else {
1188                 res[z] = vec[i];
1189             }
1190         }
1191         return new Float256Vector(res);
1192     }
1193 
1194     @Override
1195     public Float256Vector shiftLanesLeft(int j) {
1196         float[] vec = getElements();
1197         float[] res = new float[length()];
1198         for (int i = 0; i < length() - j; i++) {
1199             res[i] = vec[i + j];
1200         }
1201         return new Float256Vector(res);
1202     }
1203 
1204     @Override
1205     public Float256Vector shiftLanesRight(int j) {
1206         float[] vec = getElements();
1207         float[] res = new float[length()];
1208         for (int i = 0; i < length() - j; i++){
1209             res[i + j] = vec[i];
1210         }
1211         return new Float256Vector(res);
1212     }
1213 
1214     @Override
1215     @ForceInline
1216     public Float256Vector rearrange(Vector<Float> v,
1217                                   VectorShuffle<Float> s, VectorMask<Float> m) {
1218         return this.rearrange(s).blend(v.rearrange(s), m);
1219     }
1220 
1221     @Override
1222     @ForceInline
1223     public Float256Vector rearrange(VectorShuffle<Float> o1) {
1224         Objects.requireNonNull(o1);
1225         Float256Shuffle s =  (Float256Shuffle)o1;
1226 
1227         return VectorIntrinsics.rearrangeOp(
1228             Float256Vector.class, Float256Shuffle.class, float.class, LENGTH,
1229             this, s,
1230             (v1, s_) -> v1.uOp((i, a) -> {
1231                 int ei = s_.lane(i);
1232                 return v1.lane(ei);
1233             }));
1234     }
1235 
1236     @Override
1237     @ForceInline
1238     public Float256Vector blend(Vector<Float> o1, VectorMask<Float> o2) {
1239         Objects.requireNonNull(o1);
1240         Objects.requireNonNull(o2);
1241         Float256Vector v = (Float256Vector)o1;
1242         Float256Mask   m = (Float256Mask)o2;
1243 
1244         return VectorIntrinsics.blend(
1245             Float256Vector.class, Float256Mask.class, float.class, LENGTH,
1246             this, v, m,
1247             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.lane(i) ? b : a));
1248     }
1249 
1250     // Accessors
1251 
1252     @Override
1253     public float lane(int i) {
1254         if (i < 0 || i >= LENGTH) {
1255             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1256         }
1257         int bits = (int) VectorIntrinsics.extract(
1258                                 Float256Vector.class, float.class, LENGTH,
1259                                 this, i,
1260                                 (vec, ix) -> {
1261                                     float[] vecarr = vec.getElements();
1262                                     return (long)Float.floatToIntBits(vecarr[ix]);
1263                                 });
1264         return Float.intBitsToFloat(bits);
1265     }
1266 
1267     @Override
1268     public Float256Vector with(int i, float e) {
1269         if (i < 0 || i >= LENGTH) {
1270             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1271         }
1272         return VectorIntrinsics.insert(
1273                                 Float256Vector.class, float.class, LENGTH,
1274                                 this, i, (long)Float.floatToIntBits(e),
1275                                 (v, ix, bits) -> {
1276                                     float[] res = v.getElements().clone();
1277                                     res[ix] = Float.intBitsToFloat((int)bits);
1278                                     return new Float256Vector(res);
1279                                 });
1280     }
1281 
1282     // Mask
1283 
1284     static final class Float256Mask extends AbstractMask<Float> {
1285         static final Float256Mask TRUE_MASK = new Float256Mask(true);
1286         static final Float256Mask FALSE_MASK = new Float256Mask(false);
1287 
1288         private final boolean[] bits; // Don't access directly, use getBits() instead.
1289 
1290         public Float256Mask(boolean[] bits) {
1291             this(bits, 0);
1292         }
1293 
1294         public Float256Mask(boolean[] bits, int offset) {
1295             boolean[] a = new boolean[species().length()];
1296             for (int i = 0; i < a.length; i++) {
1297                 a[i] = bits[offset + i];
1298             }
1299             this.bits = a;
1300         }
1301 
1302         public Float256Mask(boolean val) {
1303             boolean[] bits = new boolean[species().length()];
1304             Arrays.fill(bits, val);
1305             this.bits = bits;
1306         }
1307 
1308         boolean[] getBits() {
1309             return VectorIntrinsics.maybeRebox(this).bits;
1310         }
1311 
1312         @Override
1313         Float256Mask uOp(MUnOp f) {
1314             boolean[] res = new boolean[species().length()];
1315             boolean[] bits = getBits();
1316             for (int i = 0; i < species().length(); i++) {
1317                 res[i] = f.apply(i, bits[i]);
1318             }
1319             return new Float256Mask(res);
1320         }
1321 
1322         @Override
1323         Float256Mask bOp(VectorMask<Float> o, MBinOp f) {
1324             boolean[] res = new boolean[species().length()];
1325             boolean[] bits = getBits();
1326             boolean[] mbits = ((Float256Mask)o).getBits();
1327             for (int i = 0; i < species().length(); i++) {
1328                 res[i] = f.apply(i, bits[i], mbits[i]);
1329             }
1330             return new Float256Mask(res);
1331         }
1332 
1333         @Override
1334         public VectorSpecies<Float> species() {
1335             return SPECIES;
1336         }
1337 
1338         @Override
1339         public Float256Vector toVector() {
1340             float[] res = new float[species().length()];
1341             boolean[] bits = getBits();
1342             for (int i = 0; i < species().length(); i++) {
1343                 // -1 will result in the most significant bit being set in
1344                 // addition to some or all other bits
1345                 res[i] = (float) (bits[i] ? -1 : 0);
1346             }
1347             return new Float256Vector(res);
1348         }
1349 
1350         @Override
1351         @ForceInline
1352         @SuppressWarnings("unchecked")
1353         public <E> VectorMask<E> cast(VectorSpecies<E> species) {
1354             if (length() != species.length())
1355                 throw new IllegalArgumentException("VectorMask length and species length differ");
1356             Class<?> stype = species.elementType();
1357             boolean [] maskArray = toArray();
1358             if (stype == byte.class) {
1359                 return (VectorMask <E>) new Byte256Vector.Byte256Mask(maskArray);
1360             } else if (stype == short.class) {
1361                 return (VectorMask <E>) new Short256Vector.Short256Mask(maskArray);
1362             } else if (stype == int.class) {
1363                 return (VectorMask <E>) new Int256Vector.Int256Mask(maskArray);
1364             } else if (stype == long.class) {
1365                 return (VectorMask <E>) new Long256Vector.Long256Mask(maskArray);
1366             } else if (stype == float.class) {
1367                 return (VectorMask <E>) new Float256Vector.Float256Mask(maskArray);
1368             } else if (stype == double.class) {
1369                 return (VectorMask <E>) new Double256Vector.Double256Mask(maskArray);
1370             } else {
1371                 throw new UnsupportedOperationException("Bad lane type for casting.");
1372             }
1373         }
1374 
1375         // Unary operations
1376 
1377         @Override
1378         @ForceInline
1379         public Float256Mask not() {
1380             return (Float256Mask) VectorIntrinsics.unaryOp(
1381                                              VECTOR_OP_NOT, Float256Mask.class, int.class, LENGTH,
1382                                              this,
1383                                              (m1) -> m1.uOp((i, a) -> !a));
1384         }
1385 
1386         // Binary operations
1387 
1388         @Override
1389         @ForceInline
1390         public Float256Mask and(VectorMask<Float> o) {
1391             Objects.requireNonNull(o);
1392             Float256Mask m = (Float256Mask)o;
1393             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Float256Mask.class, int.class, LENGTH,
1394                                              this, m,
1395                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1396         }
1397 
1398         @Override
1399         @ForceInline
1400         public Float256Mask or(VectorMask<Float> o) {
1401             Objects.requireNonNull(o);
1402             Float256Mask m = (Float256Mask)o;
1403             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Float256Mask.class, int.class, LENGTH,
1404                                              this, m,
1405                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1406         }
1407 
1408         // Reductions
1409 
1410         @Override
1411         @ForceInline
1412         public boolean anyTrue() {
1413             return VectorIntrinsics.test(BT_ne, Float256Mask.class, int.class, LENGTH,
1414                                          this, this,
1415                                          (m, __) -> anyTrueHelper(((Float256Mask)m).getBits()));
1416         }
1417 
1418         @Override
1419         @ForceInline
1420         public boolean allTrue() {
1421             return VectorIntrinsics.test(BT_overflow, Float256Mask.class, int.class, LENGTH,
1422                                          this, VectorMask.maskAllTrue(species()),
1423                                          (m, __) -> allTrueHelper(((Float256Mask)m).getBits()));
1424         }
1425     }
1426 
1427     // Shuffle
1428 
1429     static final class Float256Shuffle extends AbstractShuffle<Float> {
1430         Float256Shuffle(byte[] reorder) {
1431             super(reorder);
1432         }
1433 
1434         public Float256Shuffle(int[] reorder) {
1435             super(reorder);
1436         }
1437 
1438         public Float256Shuffle(int[] reorder, int i) {
1439             super(reorder, i);
1440         }
1441 
1442         public Float256Shuffle(IntUnaryOperator f) {
1443             super(f);
1444         }
1445 
1446         @Override
1447         public VectorSpecies<Float> species() {
1448             return SPECIES;
1449         }
1450 
1451         @Override
1452         public FloatVector toVector() {
1453             float[] va = new float[SPECIES.length()];
1454             for (int i = 0; i < va.length; i++) {
1455               va[i] = (float) lane(i);
1456             }
1457             return FloatVector.fromArray(SPECIES, va, 0);
1458         }
1459 
1460         @Override
1461         @ForceInline
1462         @SuppressWarnings("unchecked")
1463         public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1464             if (length() != species.length())
1465                 throw new IllegalArgumentException("Shuffle length and species length differ");
1466             Class<?> stype = species.elementType();
1467             int [] shuffleArray = toArray();
1468             if (stype == byte.class) {
1469                 return (VectorShuffle<F>) new Byte256Vector.Byte256Shuffle(shuffleArray);
1470             } else if (stype == short.class) {
1471                 return (VectorShuffle<F>) new Short256Vector.Short256Shuffle(shuffleArray);
1472             } else if (stype == int.class) {
1473                 return (VectorShuffle<F>) new Int256Vector.Int256Shuffle(shuffleArray);
1474             } else if (stype == long.class) {
1475                 return (VectorShuffle<F>) new Long256Vector.Long256Shuffle(shuffleArray);
1476             } else if (stype == float.class) {
1477                 return (VectorShuffle<F>) new Float256Vector.Float256Shuffle(shuffleArray);
1478             } else if (stype == double.class) {
1479                 return (VectorShuffle<F>) new Double256Vector.Double256Shuffle(shuffleArray);
1480             } else {
1481                 throw new UnsupportedOperationException("Bad lane type for casting.");
1482             }
1483         }
1484 
1485         @Override
1486         public Float256Shuffle rearrange(VectorShuffle<Float> o) {
1487             Float256Shuffle s = (Float256Shuffle) o;
1488             byte[] r = new byte[reorder.length];
1489             for (int i = 0; i < reorder.length; i++) {
1490                 r[i] = reorder[s.reorder[i]];
1491             }
1492             return new Float256Shuffle(r);
1493         }
1494     }
1495 
1496     // VectorSpecies
1497 
1498     @Override
1499     public VectorSpecies<Float> species() {
1500         return SPECIES;
1501     }
1502 }