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     public $vectortype$ rearrange(Shuffle<$Boxtype$, Shapes.$shape$> s) {
1290         return uOp((i, a) -> {
1291             $type$[] vec = this.getElements();
1292             int ei = s.getElement(i);
1293             return vec[ei];
1294         });
1295     }
1296 
1297     @Override
1298     @ForceInline
1299     public $vectortype$ blend(Vector<$Boxtype$, Shapes.$shape$> o1, Mask<$Boxtype$, Shapes.$shape$> o2) {
1300         Objects.requireNonNull(o1);
1301         Objects.requireNonNull(o2);
1302         $vectortype$ v = ($vectortype$)o1;
1303         $masktype$   m = ($masktype$)o2;
1304 
1305         return VectorIntrinsics.blend(
1306             $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1307             this, v, m,
1308             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1309     }
1310 
1311     // Accessors
1312 
1313 #if[FP]
1314     @Override
1315     public $type$ get(int i) {
1316         if (i < 0 || i >= LENGTH) {
1317             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1318         }
1319         $bitstype$ bits = ($bitstype$) VectorIntrinsics.extract(
1320                                 $vectortype$.class, $type$.class, LENGTH,
1321                                 this, i,
1322                                 (vec, ix) -> {
1323                                     $type$[] vecarr = vec.getElements();
1324                                     return (long)$Type$.$type$To$Bitstype$Bits(vecarr[ix]);
1325                                 });
1326         return $Type$.$bitstype$BitsTo$Fptype$(bits);
1327     }
1328 
1329     @Override
1330     public $vectortype$ with(int i, $type$ e) {
1331         if (i < 0 || i >= LENGTH) {
1332             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1333         }
1334         return VectorIntrinsics.insert(
1335                                 $vectortype$.class, $type$.class, LENGTH,
1336                                 this, i, (long)$Type$.$type$To$Bitstype$Bits(e),
1337                                 (v, ix, bits) -> {
1338                                     $type$[] res = v.getElements().clone();
1339                                     res[ix] = $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits);
1340                                     return new $vectortype$(res);
1341                                 });
1342     }
1343 #else[FP]
1344     @Override
1345     public $type$ get(int i) {
1346         if (i < 0 || i >= LENGTH) {
1347             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1348         }
1349         return ($type$) VectorIntrinsics.extract(
1350                                 $vectortype$.class, $type$.class, LENGTH,
1351                                 this, i,
1352                                 (vec, ix) -> {
1353                                     $type$[] vecarr = vec.getElements();
1354                                     return (long)vecarr[ix];
1355                                 });
1356     }
1357 
1358     @Override
1359     public $vectortype$ with(int i, $type$ e) {
1360         if (i < 0 || i >= LENGTH) {
1361             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1362         }
1363         return VectorIntrinsics.insert(
1364                                 $vectortype$.class, $type$.class, LENGTH,
1365                                 this, i, (long)e,
1366                                 (v, ix, bits) -> {
1367                                     $type$[] res = v.getElements().clone();
1368                                     res[ix] = ($type$)bits;
1369                                     return new $vectortype$(res);
1370                                 });
1371     }
1372 #end[FP]
1373 
1374     // Mask
1375 
1376     static final class $masktype$ extends AbstractMask<$Boxtype$, Shapes.$shape$> {
1377         static final $masktype$ TRUE_MASK = new $masktype$(true);
1378         static final $masktype$ FALSE_MASK = new $masktype$(false);
1379 
1380         // FIXME: was temporarily put here to simplify rematerialization support in the JVM
1381         private final boolean[] bits; // Don't access directly, use getBits() instead.
1382 
1383         public $masktype$(boolean[] bits) {
1384             this(bits, 0);
1385         }
1386 
1387         public $masktype$(boolean[] bits, int offset) {
1388             boolean[] a = new boolean[species().length()];
1389             for (int i = 0; i < a.length; i++) {
1390                 a[i] = bits[offset + i];
1391             }
1392             this.bits = a;
1393         }
1394 
1395         public $masktype$(boolean val) {
1396             boolean[] bits = new boolean[species().length()];
1397             Arrays.fill(bits, val);
1398             this.bits = bits;
1399         }
1400 
1401         boolean[] getBits() {
1402             return VectorIntrinsics.maybeRebox(this).bits;
1403         }
1404 
1405         @Override
1406         $masktype$ uOp(MUnOp f) {
1407             boolean[] res = new boolean[species().length()];
1408             boolean[] bits = getBits();
1409             for (int i = 0; i < species().length(); i++) {
1410                 res[i] = f.apply(i, bits[i]);
1411             }
1412             return new $masktype$(res);
1413         }
1414 
1415         @Override
1416         $masktype$ bOp(Mask<$Boxtype$, Shapes.$shape$> o, MBinOp f) {
1417             boolean[] res = new boolean[species().length()];
1418             boolean[] bits = getBits();
1419             boolean[] mbits = (($masktype$)o).getBits();
1420             for (int i = 0; i < species().length(); i++) {
1421                 res[i] = f.apply(i, bits[i], mbits[i]);
1422             }
1423             return new $masktype$(res);
1424         }
1425 
1426         @Override
1427         public $Type$$bits$Species species() {
1428             return SPECIES;
1429         }
1430 
1431         @Override
1432         public $vectortype$ toVector() {
1433             $type$[] res = new $type$[species().length()];
1434             boolean[] bits = getBits();
1435             for (int i = 0; i < species().length(); i++) {
1436                 // -1 will result in the most significant bit being set in
1437                 // addition to some or all other bits
1438                 res[i] = ($type$) (bits[i] ? -1 : 0);
1439             }
1440             return new $vectortype$(res);
1441         }
1442 
1443         // Unary operations
1444 
1445         @Override
1446         @ForceInline
1447         public $masktype$ not() {
1448             return ($masktype$) VectorIntrinsics.unaryOp(
1449                                              VECTOR_OP_NOT, $masktype$.class, $bitstype$.class, LENGTH,
1450                                              this,
1451                                              (m1) -> m1.uOp((i, a) -> !a));
1452         }
1453 
1454         // Binary operations
1455 
1456         @Override
1457         @ForceInline
1458         public $masktype$ and(Mask<$Boxtype$,Shapes.$shape$> o) {
1459             Objects.requireNonNull(o);
1460             $masktype$ m = ($masktype$)o;
1461             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1462                                              this, m,
1463                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1464         }
1465 
1466         @Override
1467         @ForceInline
1468         public $masktype$ or(Mask<$Boxtype$,Shapes.$shape$> o) {
1469             Objects.requireNonNull(o);
1470             $masktype$ m = ($masktype$)o;
1471             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, $masktype$.class, $bitstype$.class, LENGTH,
1472                                              this, m,
1473                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1474         }
1475 
1476         // Reductions
1477 
1478         @Override
1479         @ForceInline
1480         public boolean anyTrue() {
1481             return VectorIntrinsics.test(COND_notZero, $masktype$.class, $bitstype$.class, LENGTH,
1482                                          this, this,
1483                                          (m1, m2) -> super.anyTrue());
1484         }
1485 
1486         @Override
1487         @ForceInline
1488         public boolean allTrue() {
1489             return VectorIntrinsics.test(COND_carrySet, $masktype$.class, $bitstype$.class, LENGTH,
1490                                          this, species().maskAllTrue(),
1491                                          (m1, m2) -> super.allTrue());
1492         }
1493     }
1494 
1495     // Shuffle
1496 
1497     static final class $shuffletype$ extends AbstractShuffle<$Boxtype$, Shapes.$shape$> {
1498         $shuffletype$(byte[] reorder) {
1499             super(reorder);
1500         }
1501 
1502         public $shuffletype$(int[] reorder) {
1503             super(reorder);
1504         }
1505 
1506         public $shuffletype$(int[] reorder, int i) {
1507             super(reorder, i);
1508         }
1509 
1510         public $shuffletype$(IntUnaryOperator f) {
1511             super(f);
1512         }
1513 
1514         @Override
1515         public $Type$$bits$Species species() {
1516             return SPECIES;
1517         }
1518 
1519         @Override
1520         public $vectortype$ toVector() {
1521             $type$[] va = new $type$[SPECIES.length()];
1522             for (int i = 0; i < va.length; i++) {
1523               va[i] = ($type$) getElement(i);
1524             }
1525             return species().fromArray(va, 0);
1526         }
1527 
1528         @Override
1529         public $shuffletype$ rearrange(Vector.Shuffle<$Boxtype$, Shapes.$shape$> o) {
1530             $shuffletype$ s = ($shuffletype$) o;
1531             byte[] r = new byte[reorder.length];
1532             for (int i = 0; i < reorder.length; i++) {
1533                 r[i] = reorder[s.reorder[i]];
1534             }
1535             return new $shuffletype$(r);
1536         }
1537     }
1538 
1539     // Species
1540 
1541     @Override
1542     public $Type$$bits$Species species() {
1543         return SPECIES;
1544     }
1545 
1546     static final class $Type$$bits$Species extends $Type$Species<Shapes.$shape$> {
1547         static final int BIT_SIZE = Shapes.$Shape$.bitSize();
1548 
1549         static final int LENGTH = BIT_SIZE / $Boxtype$.SIZE;
1550 
1551         @Override
1552         public String toString() {
1553            StringBuilder sb = new StringBuilder("Shape[");
1554            sb.append(bitSize()).append(" bits, ");
1555            sb.append(length()).append(" ").append($type$.class.getSimpleName()).append("s x ");
1556            sb.append(elementSize()).append(" bits");
1557            sb.append("]");
1558            return sb.toString();
1559         }
1560 
1561         @Override
1562         @ForceInline
1563         public int bitSize() {
1564             return BIT_SIZE;
1565         }
1566 
1567         @Override
1568         @ForceInline
1569         public int length() {
1570             return LENGTH;
1571         }
1572 
1573         @Override
1574         @ForceInline
1575         public Class<$Boxtype$> elementType() {
1576             return $type$.class;
1577         }
1578 
1579         @Override
1580         @ForceInline
1581         public int elementSize() {
1582             return $Boxtype$.SIZE;
1583         }
1584 
1585         @Override
1586         @ForceInline
1587         public Shapes.$shape$ shape() {
1588             return Shapes.$Shape$;
1589         }
1590 
1591         @Override
1592         $vectortype$ op(FOp f) {
1593             $type$[] res = new $type$[length()];
1594             for (int i = 0; i < length(); i++) {
1595                 res[i] = f.apply(i);
1596             }
1597             return new $vectortype$(res);
1598         }
1599 
1600         @Override
1601         $vectortype$ op(Mask<$Boxtype$, Shapes.$shape$> o, FOp f) {
1602             $type$[] res = new $type$[length()];
1603             boolean[] mbits = (($masktype$)o).getBits();
1604             for (int i = 0; i < length(); i++) {
1605                 if (mbits[i]) {
1606                     res[i] = f.apply(i);
1607                 }
1608             }
1609             return new $vectortype$(res);
1610         }
1611 
1612         // Factories
1613 
1614         @Override
1615         public $masktype$ maskFromValues(boolean... bits) {
1616             return new $masktype$(bits);
1617         }
1618 
1619         @Override
1620         public $masktype$ maskFromArray(boolean[] bits, int i) {
1621             return new $masktype$(bits, i);
1622         }
1623 
1624         @Override
1625         public $shuffletype$ shuffle(IntUnaryOperator f) {
1626             return new $shuffletype$(f);
1627         }
1628 
1629         @Override
1630         public $shuffletype$ shuffleIota() {
1631             return new $shuffletype$(AbstractShuffle.IDENTITY);
1632         }
1633 
1634         @Override
1635         public $shuffletype$ shuffleFromValues(int... ixs) {
1636             return new $shuffletype$(ixs);
1637         }
1638 
1639         @Override
1640         public $shuffletype$ shuffleFromArray(int[] ixs, int i) {
1641             return new $shuffletype$(ixs, i);
1642         }
1643 
1644 #if[FP]
1645         @Override
1646         @ForceInline
1647         public $vectortype$ zero() {
1648             return VectorIntrinsics.broadcastCoerced($vectortype$.class, $type$.class, LENGTH,
1649                                                      $Type$.$type$To$Bitstype$Bits(0.0f),
1650                                                      (z -> ZERO));
1651         }
1652 
1653         @Override
1654         @ForceInline
1655         public $vectortype$ broadcast($type$ e) {
1656             return VectorIntrinsics.broadcastCoerced(
1657                 $vectortype$.class, $type$.class, LENGTH,
1658                 $Type$.$type$To$Bitstype$Bits(e),
1659                 ((long bits) -> SPECIES.op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
1660         }
1661 #end[FP]
1662 #if[BITWISE]
1663         @Override
1664         @ForceInline
1665         public $vectortype$ zero() {
1666             return VectorIntrinsics.broadcastCoerced($vectortype$.class, $type$.class, LENGTH,
1667                                                      0,
1668                                                      (z -> ZERO));
1669         }
1670 
1671         @Override
1672         @ForceInline
1673         public $vectortype$ broadcast($type$ e) {
1674             return VectorIntrinsics.broadcastCoerced(
1675                 $vectortype$.class, $type$.class, LENGTH,
1676                 e,
1677                 ((long bits) -> SPECIES.op(i -> ($type$)bits)));
1678         }
1679 #end[BITWISE]
1680 
1681         @Override
1682         @ForceInline
1683         public $masktype$ maskAllTrue() {
1684             return VectorIntrinsics.broadcastCoerced($masktype$.class, $bitstype$.class, LENGTH,
1685                                                      ($bitstype$)-1,
1686                                                      (z -> $masktype$.TRUE_MASK));
1687         }
1688 
1689         @Override
1690         @ForceInline
1691         public $masktype$ maskAllFalse() {
1692             return VectorIntrinsics.broadcastCoerced($masktype$.class, $bitstype$.class, LENGTH,
1693                                                      0,
1694                                                      (z -> $masktype$.FALSE_MASK));
1695         }
1696 
1697         @Override
1698         @ForceInline
1699         public $vectortype$ scalars($type$... es) {
1700             Objects.requireNonNull(es);
1701             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
1702             return VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1703                                          es, Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
1704                                          es, ix,
1705                                          (c, idx) -> op(n -> c[idx + n]));
1706         }
1707 
1708         @Override
1709         @ForceInline
1710         public $vectortype$ fromArray($type$[] a, int ix) {
1711             Objects.requireNonNull(a);
1712             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1713             return VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1714                                          a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
1715                                          a, ix,
1716                                          (c, idx) -> op(n -> c[idx + n]));
1717         }
1718 
1719         @Override
1720         @ForceInline
1721         public $vectortype$ fromArray($type$[] a, int ax, Mask<$Boxtype$, Shapes.$shape$> m) {
1722             // @@@ This can result in out of bounds errors for unset mask lanes
1723             return zero().blend(fromArray(a, ax), m);
1724         }
1725 
1726         @Override
1727         @ForceInline
1728         public $vectortype$ fromByteArray(byte[] a, int ix) {
1729             // @@@ Endianess
1730             Objects.requireNonNull(a);
1731             ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
1732             return VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1733                                          a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
1734                                          a, ix,
1735                                          (c, idx) -> {
1736                                              ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
1737                                              $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
1738                                              return op(i -> tb.get());
1739                                          });
1740         }
1741 
1742         @Override
1743         @ForceInline
1744         public $vectortype$ fromByteArray(byte[] a, int ix, Mask<$Boxtype$, Shapes.$shape$> m) {
1745             // @@@ This can result in out of bounds errors for unset mask lanes
1746             return zero().blend(fromByteArray(a, ix), m);
1747         }
1748 
1749         @Override
1750         @ForceInline
1751         public $vectortype$ fromByteBuffer(ByteBuffer bb, int ix) {
1752             // @@@ Endianess
1753             if (bb.order() != ByteOrder.nativeOrder()) {
1754                 throw new IllegalArgumentException();
1755             }
1756             ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
1757             return VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1758                                          U.getObject(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
1759                                          bb, ix,
1760                                          (c, idx) -> {
1761                                              ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
1762                                              $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
1763                                              return op(i -> tb.get());
1764                                          });
1765         }
1766 
1767         @Override
1768         @ForceInline
1769         public $vectortype$ fromByteBuffer(ByteBuffer bb, int ix, Mask<$Boxtype$, Shapes.$shape$> m) {
1770             // @@@ This can result in out of bounds errors for unset mask lanes
1771             return zero().blend(fromByteBuffer(bb, ix), m);
1772         }
1773 
1774         @Override
1775         @ForceInline
1776         @SuppressWarnings("unchecked")
1777         public <F, T extends Shape> $vectortype$ cast(Vector<F, T> o) {
1778             if (o.length() != LENGTH)
1779                 throw new IllegalArgumentException("Vector length this species length differ");
1780 
1781             return VectorIntrinsics.cast(
1782                 o.getClass(),
1783                 o.elementType(), LENGTH,
1784                 $type$.class, LENGTH,
1785                 o, this,
1786                 (s, v) -> s.castDefault(v)
1787             );
1788         }
1789 
1790         @SuppressWarnings("unchecked")
1791         @ForceInline
1792         private <F, T extends Shape> $vectortype$ castDefault(Vector<F, T> v) {
1793             // Allocate array of required size
1794             int limit = length();
1795             $type$[] a = new $type$[limit];
1796 
1797             Class<?> vtype = v.species().elementType();
1798             if (vtype == byte.class) {
1799                 ByteVector<T> tv = (ByteVector<T>)v;
1800                 for (int i = 0; i < limit; i++) {
1801                     a[i] = ($type$) tv.get(i);
1802                 }
1803             } else if (vtype == short.class) {
1804                 ShortVector<T> tv = (ShortVector<T>)v;
1805                 for (int i = 0; i < limit; i++) {
1806                     a[i] = ($type$) tv.get(i);
1807                 }
1808             } else if (vtype == int.class) {
1809                 IntVector<T> tv = (IntVector<T>)v;
1810                 for (int i = 0; i < limit; i++) {
1811                     a[i] = ($type$) tv.get(i);
1812                 }
1813             } else if (vtype == long.class){
1814                 LongVector<T> tv = (LongVector<T>)v;
1815                 for (int i = 0; i < limit; i++) {
1816                     a[i] = ($type$) tv.get(i);
1817                 }
1818             } else if (vtype == float.class){
1819                 FloatVector<T> tv = (FloatVector<T>)v;
1820                 for (int i = 0; i < limit; i++) {
1821                     a[i] = ($type$) tv.get(i);
1822                 }
1823             } else if (vtype == double.class){
1824                 DoubleVector<T> tv = (DoubleVector<T>)v;
1825                 for (int i = 0; i < limit; i++) {
1826                     a[i] = ($type$) tv.get(i);
1827                 }
1828             } else {
1829                 throw new UnsupportedOperationException("Bad lane type for casting.");
1830             }
1831 
1832             return scalars(a);
1833         }
1834 
1835         @Override
1836         @ForceInline
1837         public <E, S extends Shape> $masktype$ cast(Mask<E, S> m) {
1838             if (m.length() != LENGTH)
1839                 throw new IllegalArgumentException("Mask length this species length differ");
1840             return new $masktype$(m.toArray());
1841         }
1842 
1843         @Override
1844         @ForceInline
1845         public <E, S extends Shape> $shuffletype$ cast(Shuffle<E, S> s) {
1846             if (s.length() != LENGTH)
1847                 throw new IllegalArgumentException("Shuffle length this species length differ");
1848             return new $shuffletype$(s.toArray());
1849         }
1850 
1851         @Override
1852         @ForceInline
1853         @SuppressWarnings("unchecked")
1854         public <F> $vectortype$ rebracket(Vector<F, Shapes.$shape$> o) {
1855             Objects.requireNonNull(o);
1856             if (o.elementType() == byte.class) {
1857                 Byte$bits$Vector so = (Byte$bits$Vector)o;
1858                 return VectorIntrinsics.reinterpret(
1859                     Byte$bits$Vector.class,
1860                     byte.class, so.length(),
1861                     $type$.class, LENGTH,
1862                     so, this,
1863                     (s, v) -> ($vectortype$) s.reshape(v)
1864                 );
1865             } else if (o.elementType() == short.class) {
1866                 Short$bits$Vector so = (Short$bits$Vector)o;
1867                 return VectorIntrinsics.reinterpret(
1868                     Short$bits$Vector.class,
1869                     short.class, so.length(),
1870                     $type$.class, LENGTH,
1871                     so, this,
1872                     (s, v) -> ($vectortype$) s.reshape(v)
1873                 );
1874             } else if (o.elementType() == int.class) {
1875                 Int$bits$Vector so = (Int$bits$Vector)o;
1876                 return VectorIntrinsics.reinterpret(
1877                     Int$bits$Vector.class,
1878                     int.class, so.length(),
1879                     $type$.class, LENGTH,
1880                     so, this,
1881                     (s, v) -> ($vectortype$) s.reshape(v)
1882                 );
1883             } else if (o.elementType() == long.class) {
1884                 Long$bits$Vector so = (Long$bits$Vector)o;
1885                 return VectorIntrinsics.reinterpret(
1886                     Long$bits$Vector.class,
1887                     long.class, so.length(),
1888                     $type$.class, LENGTH,
1889                     so, this,
1890                     (s, v) -> ($vectortype$) s.reshape(v)
1891                 );
1892             } else if (o.elementType() == float.class) {
1893                 Float$bits$Vector so = (Float$bits$Vector)o;
1894                 return VectorIntrinsics.reinterpret(
1895                     Float$bits$Vector.class,
1896                     float.class, so.length(),
1897                     $type$.class, LENGTH,
1898                     so, this,
1899                     (s, v) -> ($vectortype$) s.reshape(v)
1900                 );
1901             } else if (o.elementType() == double.class) {
1902                 Double$bits$Vector so = (Double$bits$Vector)o;
1903                 return VectorIntrinsics.reinterpret(
1904                     Double$bits$Vector.class,
1905                     double.class, so.length(),
1906                     $type$.class, LENGTH,
1907                     so, this,
1908                     (s, v) -> ($vectortype$) s.reshape(v)
1909                 );
1910             } else {
1911                 throw new InternalError("Unimplemented type");
1912             }
1913         }
1914 
1915         @Override
1916         @ForceInline
1917         @SuppressWarnings("unchecked")
1918         public <T extends Shape> $vectortype$ resize(Vector<$Boxtype$, T> o) {
1919             Objects.requireNonNull(o);
1920             if (o.bitSize() == 64) {
1921                 $Type$64Vector so = ($Type$64Vector)o;
1922                 return VectorIntrinsics.reinterpret(
1923                     $Type$64Vector.class,
1924                     $type$.class, so.length(),
1925                     $type$.class, LENGTH,
1926                     so, this,
1927                     (s, v) -> ($vectortype$) s.reshape(v)
1928                 );
1929             } else if (o.bitSize() == 128) {
1930                 $Type$128Vector so = ($Type$128Vector)o;
1931                 return VectorIntrinsics.reinterpret(
1932                     $Type$128Vector.class,
1933                     $type$.class, so.length(),
1934                     $type$.class, LENGTH,
1935                     so, this,
1936                     (s, v) -> ($vectortype$) s.reshape(v)
1937                 );
1938             } else if (o.bitSize() == 256) {
1939                 $Type$256Vector so = ($Type$256Vector)o;
1940                 return VectorIntrinsics.reinterpret(
1941                     $Type$256Vector.class,
1942                     $type$.class, so.length(),
1943                     $type$.class, LENGTH,
1944                     so, this,
1945                     (s, v) -> ($vectortype$) s.reshape(v)
1946                 );
1947             } else if (o.bitSize() == 512) {
1948                 $Type$512Vector so = ($Type$512Vector)o;
1949                 return VectorIntrinsics.reinterpret(
1950                     $Type$512Vector.class,
1951                     $type$.class, so.length(),
1952                     $type$.class, LENGTH,
1953                     so, this,
1954                     (s, v) -> ($vectortype$) s.reshape(v)
1955                 );
1956             } else if ((o.bitSize() <= 2048) && (o.bitSize() % 128 == 0)) {
1957                 throw new InternalError("Resize to scalable shape unimplemented.");
1958             } else {
1959                 throw new InternalError("Unimplemented size");
1960             }
1961         }
1962     }
1963 }