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