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.util.Arrays;
  29 import java.util.Objects;
  30 import jdk.internal.vm.annotation.ForceInline;
  31 import static jdk.incubator.vector.VectorIntrinsics.*;
  32 
  33 @SuppressWarnings("cast")
  34 final class $vectortype$ extends $abstractvectortype$<Shapes.$shape$> {
  35     static final $Type$$bits$Species SPECIES = new $Type$$bits$Species();
  36 
  37     static final $vectortype$ ZERO = new $vectortype$();
  38 
  39     static final int LENGTH = SPECIES.length();
  40 
  41     private final $type$[] vec; // Don't access directly, use getElements() instead.
  42 
  43     private $type$[] getElements() {
  44         return VectorIntrinsics.maybeRebox(this).vec;
  45     }
  46 
  47     $vectortype$() {
  48         vec = new $type$[SPECIES.length()];
  49     }
  50 
  51     $vectortype$($type$[] v) {
  52         vec = v;
  53     }
  54 
  55     @Override
  56     public int length() { return LENGTH; }
  57 
  58     // Unary operator
  59 
  60     @Override
  61     $vectortype$ uOp(FUnOp f) {
  62         $type$[] vec = getElements();
  63         $type$[] res = new $type$[length()];
  64         for (int i = 0; i < length(); i++) {
  65             res[i] = f.apply(i, vec[i]);
  66         }
  67         return new $vectortype$(res);
  68     }
  69 
  70     @Override
  71     $vectortype$ uOp(Mask<$Boxtype$, Shapes.$shape$> o, FUnOp f) {
  72         $type$[] vec = getElements();
  73         $type$[] res = new $type$[length()];
  74         boolean[] mbits = (($masktype$)o).getBits();
  75         for (int i = 0; i < length(); i++) {
  76             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
  77         }
  78         return new $vectortype$(res);
  79     }
  80 
  81     // Binary operator
  82 
  83     @Override
  84     $vectortype$ bOp(Vector<$Boxtype$, Shapes.$shape$> o, FBinOp f) {
  85         $type$[] res = new $type$[length()];
  86         $type$[] vec1 = this.getElements();
  87         $type$[] vec2 = (($vectortype$)o).getElements();
  88         for (int i = 0; i < length(); i++) {
  89             res[i] = f.apply(i, vec1[i], vec2[i]);
  90         }
  91         return new $vectortype$(res);
  92     }
  93 
  94     @Override
  95     $vectortype$ bOp(Vector<$Boxtype$, Shapes.$shape$> o1, Mask<$Boxtype$, Shapes.$shape$> o2, FBinOp f) {
  96         $type$[] res = new $type$[length()];
  97         $type$[] vec1 = this.getElements();
  98         $type$[] vec2 = (($vectortype$)o1).getElements();
  99         boolean[] mbits = (($masktype$)o2).getBits();
 100         for (int i = 0; i < length(); i++) {
 101             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
 102         }
 103         return new $vectortype$(res);
 104     }
 105 
 106     // Trinary operator
 107 
 108     @Override
 109     $vectortype$ tOp(Vector<$Boxtype$, Shapes.$shape$> o1, Vector<$Boxtype$, Shapes.$shape$> o2, FTriOp f) {
 110         $type$[] res = new $type$[length()];
 111         $type$[] vec1 = this.getElements();
 112         $type$[] vec2 = (($vectortype$)o1).getElements();
 113         $type$[] vec3 = (($vectortype$)o2).getElements();
 114         for (int i = 0; i < length(); i++) {
 115             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
 116         }
 117         return new $vectortype$(res);
 118     }
 119 
 120     @Override
 121     $vectortype$ tOp(Vector<$Boxtype$, Shapes.$shape$> o1, Vector<$Boxtype$, Shapes.$shape$> o2, Mask<$Boxtype$, Shapes.$shape$> o3, FTriOp f) {
 122         $type$[] res = new $type$[length()];
 123         $type$[] vec1 = getElements();
 124         $type$[] vec2 = (($vectortype$)o1).getElements();
 125         $type$[] vec3 = (($vectortype$)o2).getElements();
 126         boolean[] mbits = (($masktype$)o3).getBits();
 127         for (int i = 0; i < length(); i++) {
 128             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
 129         }
 130         return new $vectortype$(res);
 131     }
 132 
 133     @Override
 134     $type$ rOp($type$ v, FBinOp f) {
 135         $type$[] vec = getElements();
 136         for (int i = 0; i < length(); i++) {
 137             v = f.apply(i, v, vec[i]);
 138         }
 139         return v;
 140     }
 141 
 142     // Binary operations with scalars
 143 
 144     @Override
 145     @ForceInline
 146     public $abstractvectortype$<Shapes.$shape$> add($type$ o) {
 147         return add(SPECIES.broadcast(o));
 148     }
 149 
 150     @Override
 151     @ForceInline
 152     public $abstractvectortype$<Shapes.$shape$> add($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 153         return add(SPECIES.broadcast(o), m);
 154     }
 155 
 156     @Override
 157     @ForceInline
 158     public $abstractvectortype$<Shapes.$shape$> addSaturate($type$ o) {
 159         return addSaturate(SPECIES.broadcast(o));
 160     }
 161 
 162     @Override
 163     @ForceInline
 164     public $abstractvectortype$<Shapes.$shape$> addSaturate($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 165         return addSaturate(SPECIES.broadcast(o), m);
 166     }
 167 
 168     @Override
 169     @ForceInline
 170     public $abstractvectortype$<Shapes.$shape$> sub($type$ o) {
 171         return sub(SPECIES.broadcast(o));
 172     }
 173 
 174     @Override
 175     @ForceInline
 176     public $abstractvectortype$<Shapes.$shape$> sub($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 177         return sub(SPECIES.broadcast(o), m);
 178     }
 179 
 180     @Override
 181     @ForceInline
 182     public $abstractvectortype$<Shapes.$shape$> subSaturate($type$ o) {
 183         return subSaturate(SPECIES.broadcast(o));
 184     }
 185 
 186     @Override
 187     @ForceInline
 188     public $abstractvectortype$<Shapes.$shape$> subSaturate($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 189         return subSaturate(SPECIES.broadcast(o), m);
 190     }
 191 
 192     @Override
 193     @ForceInline
 194     public $abstractvectortype$<Shapes.$shape$> mul($type$ o) {
 195         return mul(SPECIES.broadcast(o));
 196     }
 197 
 198     @Override
 199     @ForceInline
 200     public $abstractvectortype$<Shapes.$shape$> mul($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 201         return mul(SPECIES.broadcast(o), m);
 202     }
 203 
 204     @Override
 205     @ForceInline
 206     public $abstractvectortype$<Shapes.$shape$> min($type$ o) {
 207         return min(SPECIES.broadcast(o));
 208     }
 209 
 210     @Override
 211     @ForceInline
 212     public $abstractvectortype$<Shapes.$shape$> max($type$ o) {
 213         return max(SPECIES.broadcast(o));
 214     }
 215 
 216     @Override
 217     @ForceInline
 218     public Mask<$Boxtype$, Shapes.$shape$> equal($type$ o) {
 219         return equal(SPECIES.broadcast(o));
 220     }
 221 
 222     @Override
 223     @ForceInline
 224     public Mask<$Boxtype$, Shapes.$shape$> notEqual($type$ o) {
 225         return notEqual(SPECIES.broadcast(o));
 226     }
 227 
 228     @Override
 229     @ForceInline
 230     public Mask<$Boxtype$, Shapes.$shape$> lessThan($type$ o) {
 231         return lessThan(SPECIES.broadcast(o));
 232     }
 233 
 234     @Override
 235     @ForceInline
 236     public Mask<$Boxtype$, Shapes.$shape$> lessThanEq($type$ o) {
 237         return lessThanEq(SPECIES.broadcast(o));
 238     }
 239 
 240     @Override
 241     @ForceInline
 242     public Mask<$Boxtype$, Shapes.$shape$> greaterThan($type$ o) {
 243         return greaterThan(SPECIES.broadcast(o));
 244     }
 245 
 246     @Override
 247     @ForceInline
 248     public Mask<$Boxtype$, Shapes.$shape$> greaterThanEq($type$ o) {
 249         return greaterThanEq(SPECIES.broadcast(o));
 250     }
 251 
 252     @Override
 253     @ForceInline
 254     public $abstractvectortype$<Shapes.$shape$> blend($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 255         return blend(SPECIES.broadcast(o), m);
 256     }
 257 
 258 #if[FP]
 259     @Override
 260     @ForceInline
 261     public $abstractvectortype$<Shapes.$shape$> div($type$ o) {
 262         return div(SPECIES.broadcast(o));
 263     }
 264 
 265     @Override
 266     @ForceInline
 267     public $abstractvectortype$<Shapes.$shape$> div($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 268         return div(SPECIES.broadcast(o), m);
 269     }
 270 
 271     @Override
 272     @ForceInline
 273     public $abstractvectortype$<Shapes.$shape$> atan2($type$ o) {
 274         return atan2(SPECIES.broadcast(o));
 275     }
 276 
 277     @Override
 278     @ForceInline
 279     public $abstractvectortype$<Shapes.$shape$> atan2($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 280         return atan2(SPECIES.broadcast(o), m);
 281     }
 282 
 283     @Override
 284     @ForceInline
 285     public $abstractvectortype$<Shapes.$shape$> pow($type$ o) {
 286         return pow(SPECIES.broadcast(o));
 287     }
 288 
 289     @Override
 290     @ForceInline
 291     public $abstractvectortype$<Shapes.$shape$> pow($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 292         return pow(SPECIES.broadcast(o), m);
 293     }
 294 
 295     @Override
 296     @ForceInline
 297     public $abstractvectortype$<Shapes.$shape$> fma($type$ o1, $type$ o2) {
 298         return fma(SPECIES.broadcast(o1), SPECIES.broadcast(o2));
 299     }
 300 
 301     @Override
 302     @ForceInline
 303     public $abstractvectortype$<Shapes.$shape$> fma($type$ o1, $type$ o2, Mask<$Boxtype$,Shapes.$shape$> m) {
 304         return fma(SPECIES.broadcast(o1), SPECIES.broadcast(o2), m);
 305     }
 306 
 307     @Override
 308     @ForceInline
 309     public $abstractvectortype$<Shapes.$shape$> hypot($type$ o) {
 310         return hypot(SPECIES.broadcast(o));
 311     }
 312 
 313     @Override
 314     @ForceInline
 315     public $abstractvectortype$<Shapes.$shape$> hypot($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 316         return hypot(SPECIES.broadcast(o), m);
 317     }
 318 #end[FP]
 319 
 320 #if[BITWISE]
 321     @Override
 322     @ForceInline
 323     public $abstractvectortype$<Shapes.$shape$> and($type$ o) {
 324         return and(SPECIES.broadcast(o));
 325     }
 326 
 327     @Override
 328     @ForceInline
 329     public $abstractvectortype$<Shapes.$shape$> and($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 330         return and(SPECIES.broadcast(o), m);
 331     }
 332 
 333     @Override
 334     @ForceInline
 335     public $abstractvectortype$<Shapes.$shape$> or($type$ o) {
 336         return or(SPECIES.broadcast(o));
 337     }
 338 
 339     @Override
 340     @ForceInline
 341     public $abstractvectortype$<Shapes.$shape$> or($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 342         return or(SPECIES.broadcast(o), m);
 343     }
 344 
 345     @Override
 346     @ForceInline
 347     public $abstractvectortype$<Shapes.$shape$> xor($type$ o) {
 348         return xor(SPECIES.broadcast(o));
 349     }
 350 
 351     @Override
 352     @ForceInline
 353     public $abstractvectortype$<Shapes.$shape$> xor($type$ o, Mask<$Boxtype$,Shapes.$shape$> m) {
 354         return xor(SPECIES.broadcast(o), m);
 355     }
 356 #end[BITWISE]
 357 
 358 
 359     // Unary operations
 360 
 361 #if[intOrFP]
 362     @Override
 363     @ForceInline
 364     public $vectortype$ abs() {
 365         return ($vectortype$) VectorIntrinsics.unaryOp(
 366             VECTOR_OP_ABS, $vectortype$.class, $type$.class, LENGTH,
 367             this,
 368             v1 -> (($vectortype$)v1).uOp((i, a) -> ($type$) Math.abs(a)));
 369     }
 370 
 371     @Override
 372     @ForceInline
 373     public $vectortype$ neg() {
 374         return ($vectortype$) VectorIntrinsics.unaryOp(
 375             VECTOR_OP_NEG, $vectortype$.class, $type$.class, LENGTH,
 376             this,
 377             v1 -> (($vectortype$)v1).uOp((i, a) -> ($type$) -a));
 378     }
 379 #end[intOrFP]
 380 
 381 #if[FP]
 382     @Override
 383     @ForceInline
 384     public $vectortype$ div(Vector<$Boxtype$,Shapes.$shape$> o) {
 385         Objects.requireNonNull(o);
 386         $vectortype$ v = ($vectortype$)o;
 387         return ($vectortype$) VectorIntrinsics.binaryOp(
 388             VECTOR_OP_DIV, $vectortype$.class, $type$.class, LENGTH,
 389             this, v,
 390             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a / b)));
 391     }
 392 
 393     @Override
 394     @ForceInline
 395     public $vectortype$ sqrt() {
 396         return ($vectortype$) VectorIntrinsics.unaryOp(
 397             VECTOR_OP_SQRT, $vectortype$.class, $type$.class, LENGTH,
 398             this,
 399             v1 -> (($vectortype$)v1).uOp((i, a) -> ($type$) Math.sqrt((double) a)));
 400     }
 401 #end[FP]
 402 
 403 #if[BITWISE]
 404     @Override
 405     @ForceInline
 406     public $vectortype$ not() {
 407         return ($vectortype$) VectorIntrinsics.unaryOp(
 408             VECTOR_OP_NOT, $vectortype$.class, $type$.class, LENGTH,
 409             this,
 410             v1 -> (($vectortype$)v1).uOp((i, a) -> ($type$) ~a));
 411     }
 412 #end[BITWISE]
 413     // Binary operations
 414 
 415     @Override
 416     @ForceInline
 417     public $vectortype$ add(Vector<$Boxtype$,Shapes.$shape$> o) {
 418         Objects.requireNonNull(o);
 419         $vectortype$ v = ($vectortype$)o;
 420         return ($vectortype$) VectorIntrinsics.binaryOp(
 421             VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
 422             this, v,
 423             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a + b)));
 424     }
 425 
 426     @Override
 427     @ForceInline
 428     public $vectortype$ sub(Vector<$Boxtype$,Shapes.$shape$> o) {
 429         Objects.requireNonNull(o);
 430         $vectortype$ v = ($vectortype$)o;
 431         return ($vectortype$) VectorIntrinsics.binaryOp(
 432             VECTOR_OP_SUB, $vectortype$.class, $type$.class, LENGTH,
 433             this, v,
 434             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a - b)));
 435     }
 436 
 437     @Override
 438     @ForceInline
 439     public $vectortype$ mul(Vector<$Boxtype$,Shapes.$shape$> o) {
 440         Objects.requireNonNull(o);
 441         $vectortype$ v = ($vectortype$)o;
 442         return ($vectortype$) VectorIntrinsics.binaryOp(
 443             VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
 444             this, v,
 445             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a * b)));
 446     }
 447 
 448 #if[intOrFP]
 449     @Override
 450     @ForceInline
 451     public $vectortype$ add(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 452         // TODO: use better default impl: bOp(o, m, (i, a, b) -> ($type$)(a + b));
 453         return blend(add(v), m);
 454     }
 455 
 456     @Override
 457     @ForceInline
 458     public $vectortype$ sub(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 459         // TODO: use better default impl: bOp(o, m, (i, a, b) -> ($type$)(a - b));
 460         return blend(sub(v), m);
 461     }
 462 
 463     @Override
 464     @ForceInline
 465     public $vectortype$ mul(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 466         // TODO: use better default impl: bOp(o, m, (i, a, b) -> ($type$)(a * b));
 467         return blend(mul(v), m);
 468     }
 469 #end[intOrFP]
 470 
 471 #if[FP]
 472     @Override
 473     @ForceInline
 474     public $vectortype$ div(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 475         // TODO: use better default impl: bOp(o, m, (i, a, b) -> ($type$)(a / b));
 476         return blend(div(v), m);
 477     }
 478 #end[FP]
 479 
 480 #if[BITWISE]
 481     @Override
 482     @ForceInline
 483     public $vectortype$ and(Vector<$Boxtype$,Shapes.$shape$> o) {
 484         Objects.requireNonNull(o);
 485         $vectortype$ v = ($vectortype$)o;
 486         return ($vectortype$) VectorIntrinsics.binaryOp(
 487             VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
 488             this, v,
 489             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a & b)));
 490     }
 491 
 492     @Override
 493     @ForceInline
 494     public $vectortype$ or(Vector<$Boxtype$,Shapes.$shape$> o) {
 495         Objects.requireNonNull(o);
 496         $vectortype$ v = ($vectortype$)o;
 497         return ($vectortype$) VectorIntrinsics.binaryOp(
 498             VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
 499             this, v,
 500             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a | b)));
 501     }
 502 
 503     @Override
 504     @ForceInline
 505     public $vectortype$ xor(Vector<$Boxtype$,Shapes.$shape$> o) {
 506         Objects.requireNonNull(o);
 507         $vectortype$ v = ($vectortype$)o;
 508         return ($vectortype$) VectorIntrinsics.binaryOp(
 509             VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
 510             this, v,
 511             (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(a ^ b)));
 512     }
 513 
 514     @Override
 515     @ForceInline
 516     public $vectortype$ and(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 517         return blend(and(v), m);
 518     }
 519 
 520     @Override
 521     @ForceInline
 522     public $vectortype$ or(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 523         return blend(or(v), m);
 524     }
 525 
 526     @Override
 527     @ForceInline
 528     public $vectortype$ xor(Vector<$Boxtype$,Shapes.$shape$> v, Mask<$Boxtype$, Shapes.$shape$> m) {
 529         return blend(xor(v), m);
 530     }
 531 
 532     @Override
 533     @ForceInline
 534     public $vectortype$ shiftL(int s) {
 535         return ($vectortype$) VectorIntrinsics.broadcastInt(
 536             VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
 537             this, s,
 538             (v, i) -> v.uOp((__, a) -> ($type$) (a << i)));
 539     }
 540 
 541     @Override
 542     @ForceInline
 543     public $vectortype$ shiftR(int s) {
 544         return ($vectortype$) VectorIntrinsics.broadcastInt(
 545             VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
 546             this, s,
 547             (v, i) -> v.uOp((__, a) -> ($type$) (a >>> i)));
 548     }
 549 
 550     @Override
 551     @ForceInline
 552     public $vectortype$ aShiftR(int s) {
 553         return ($vectortype$) VectorIntrinsics.broadcastInt(
 554             VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
 555             this, s,
 556             (v, i) -> v.uOp((__, a) -> ($type$) (a >> i)));
 557     }
 558 #end[BITWISE]
 559 
 560     // Ternary operations
 561 
 562 #if[FP]
 563     @Override
 564     @ForceInline
 565     public $vectortype$ fma(Vector<$Boxtype$,Shapes.$shape$> o1, Vector<$Boxtype$,Shapes.$shape$> o2) {
 566         Objects.requireNonNull(o1);
 567         Objects.requireNonNull(o2);
 568         $vectortype$ v1 = ($vectortype$)o1;
 569         $vectortype$ v2 = ($vectortype$)o2;
 570         return ($vectortype$) VectorIntrinsics.ternaryOp(
 571             VECTOR_OP_FMA, $vectortype$.class, $type$.class, LENGTH,
 572             this, v1, v2,
 573             (w1, w2, w3) -> w1.tOp(w2, w3, (i, a, b, c) -> Math.fma(a, b, c)));
 574     }
 575 #end[FP]
 576 
 577     // Type specific horizontal reductions
 578 
 579 #if[BITWISE]
 580     @Override
 581     @ForceInline
 582     public $type$ addAll() {
 583         return ($type$) VectorIntrinsics.reductionCoerced(
 584             VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
 585             this,
 586             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b)));
 587     }
 588 
 589     @Override
 590     @ForceInline
 591     public $type$ andAll() {
 592         return ($type$) VectorIntrinsics.reductionCoerced(
 593             VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
 594             this,
 595             v -> (long) v.rOp(($type$) -1, (i, a, b) -> ($type$) (a & b)));
 596     }
 597 
 598     @Override
 599     @ForceInline
 600     public $type$ subAll() {
 601         return ($type$) VectorIntrinsics.reductionCoerced(
 602             VECTOR_OP_SUB, $vectortype$.class, $type$.class, LENGTH,
 603             this,
 604             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a - b)));
 605     }
 606 #end[BITWISE]
 607 #if[intOrLong]
 608 
 609     @Override
 610     @ForceInline
 611     public $type$ mulAll() {
 612         return ($type$) VectorIntrinsics.reductionCoerced(
 613             VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
 614             this,
 615             v -> (long) v.rOp(($type$) 1, (i, a, b) -> ($type$) (a * b)));
 616     }
 617 
 618     @Override
 619     @ForceInline
 620     public $type$ orAll() {
 621         return ($type$) VectorIntrinsics.reductionCoerced(
 622             VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
 623             this,
 624             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a | b)));
 625     }
 626 
 627     @Override
 628     @ForceInline
 629     public $type$ xorAll() {
 630         return ($type$) VectorIntrinsics.reductionCoerced(
 631             VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
 632             this,
 633             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a ^ b)));
 634     }
 635 #end[intOrLong]
 636 #if[FP]
 637     @Override
 638     @ForceInline
 639     public $type$ addAll() {
 640         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
 641                                 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
 642                                 this,
 643                                 v -> {
 644                                     $type$ r = v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b));
 645                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
 646                                 });
 647         return $Type$.$bitstype$BitsTo$Fptype$(bits);
 648     }
 649 
 650     @Override
 651     @ForceInline
 652     public $type$ subAll() {
 653         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
 654                                 VECTOR_OP_SUB, $vectortype$.class, $type$.class, LENGTH,
 655                                 this,
 656                                 v -> {
 657                                     $type$ r = v.rOp(($type$) 0, (i, a, b) -> ($type$) (a - b));
 658                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
 659                                 });
 660         return $Type$.$bitstype$BitsTo$Fptype$(bits);
 661     }
 662 
 663     @Override
 664     @ForceInline
 665     public $type$ mulAll() {
 666         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
 667                                 VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
 668                                 this,
 669                                 v -> {
 670                                     $type$ r = v.rOp(($type$) 1, (i, a, b) -> ($type$) (a * b));
 671                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
 672                                 });
 673         return $Type$.$bitstype$BitsTo$Fptype$(bits);
 674     }
 675 #end[FP]
 676 
 677     // Memory operations
 678 
 679     @Override
 680     @ForceInline
 681     public void intoArray($type$[] a, int ix) {
 682         Objects.requireNonNull(a);
 683         ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 684         VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
 685                                a, ix, this,
 686                                (arr, idx, v) -> v.forEach((i, a_) -> (($type$[])arr)[idx + i] = a_));
 687     }
 688 
 689     @Override
 690     @ForceInline
 691     public void intoArray($type$[] a, int ax, Mask<$Boxtype$, Shapes.$shape$> m) {
 692         // TODO: use better default impl: forEach(m, (i, a_) -> a[ax + i] = a_);
 693         $vectortype$ oldVal = SPECIES.fromArray(a, ax);
 694         $vectortype$ newVal = oldVal.blend(this, m);
 695         newVal.intoArray(a, ax);
 696     }
 697 
 698     //
 699 
 700     @Override
 701     public String toString() {
 702         return Arrays.toString(getElements());
 703     }
 704 
 705     @Override
 706     public boolean equals(Object o) {
 707         if (this == o) return true;
 708         if (o == null || this.getClass() != o.getClass()) return false;
 709 
 710         $vectortype$ that = ($vectortype$) o;
 711         return Arrays.equals(this.getElements(), that.getElements());
 712     }
 713 
 714     @Override
 715     public int hashCode() {
 716         return Arrays.hashCode(vec);
 717     }
 718 
 719     // Binary test
 720 
 721     @Override
 722     $masktype$ bTest(Vector<$Boxtype$, Shapes.$shape$> o, FBinTest f) {
 723         $type$[] vec1 = getElements();
 724         $type$[] vec2 = (($vectortype$)o).getElements();
 725         boolean[] bits = new boolean[length()];
 726         for (int i = 0; i < length(); i++){
 727             bits[i] = f.apply(i, vec1[i], vec2[i]);
 728         }
 729         return new $masktype$(bits);
 730     }
 731 
 732     // Comparisons
 733 
 734     @Override
 735     @ForceInline
 736     public $masktype$ equal(Vector<$Boxtype$, Shapes.$shape$> o) {
 737         Objects.requireNonNull(o);
 738         $vectortype$ v = ($vectortype$)o;
 739 
 740         return ($masktype$) VectorIntrinsics.compare(
 741             BT_eq, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 742             this, v,
 743             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b));
 744     }
 745 
 746     @Override
 747     @ForceInline
 748     public $masktype$ notEqual(Vector<$Boxtype$, Shapes.$shape$> o) {
 749         Objects.requireNonNull(o);
 750         $vectortype$ v = ($vectortype$)o;
 751 
 752         return ($masktype$) VectorIntrinsics.compare(
 753             BT_ne, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 754             this, v,
 755             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b));
 756     }
 757 
 758     @Override
 759     @ForceInline
 760     public $masktype$ lessThan(Vector<$Boxtype$, Shapes.$shape$> o) {
 761         Objects.requireNonNull(o);
 762         $vectortype$ v = ($vectortype$)o;
 763 
 764         return ($masktype$) VectorIntrinsics.compare(
 765             BT_lt, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 766             this, v,
 767             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b));
 768     }
 769 
 770     @Override
 771     @ForceInline
 772     public $masktype$ lessThanEq(Vector<$Boxtype$, Shapes.$shape$> o) {
 773         Objects.requireNonNull(o);
 774         $vectortype$ v = ($vectortype$)o;
 775 
 776         return ($masktype$) VectorIntrinsics.compare(
 777             BT_le, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 778             this, v,
 779             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b));
 780     }
 781 
 782     @Override
 783     @ForceInline
 784     public $masktype$ greaterThan(Vector<$Boxtype$, Shapes.$shape$> o) {
 785         Objects.requireNonNull(o);
 786         $vectortype$ v = ($vectortype$)o;
 787 
 788         return ($masktype$) VectorIntrinsics.compare(
 789             BT_gt, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 790             this, v,
 791             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b));
 792     }
 793 
 794     @Override
 795     @ForceInline
 796     public $masktype$ greaterThanEq(Vector<$Boxtype$, Shapes.$shape$> o) {
 797         Objects.requireNonNull(o);
 798         $vectortype$ v = ($vectortype$)o;
 799 
 800         return ($masktype$) VectorIntrinsics.compare(
 801             BT_ge, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 802             this, v,
 803             (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
 804     }
 805 
 806     // Foreach
 807 
 808     @Override
 809     void forEach(FUnCon f) {
 810         $type$[] vec = getElements();
 811         for (int i = 0; i < length(); i++) {
 812             f.apply(i, vec[i]);
 813         }
 814     }
 815 
 816     @Override
 817     void forEach(Mask<$Boxtype$, Shapes.$shape$> o, FUnCon f) {
 818         boolean[] mbits = (($masktype$)o).getBits();
 819         forEach((i, a) -> {
 820             if (mbits[i]) { f.apply(i, a); }
 821         });
 822     }
 823 
 824 #if[FP]
 825     $bitsvectortype$ toBits() {
 826         $type$[] vec = getElements();
 827         $bitstype$[] res = new $bitstype$[this.species().length()];
 828         for(int i = 0; i < this.species().length(); i++){
 829             res[i] = $Type$.$type$To$Bitstype$Bits(vec[i]);
 830         }
 831         return new $bitsvectortype$(res);
 832     }
 833 #end[FP]
 834 
 835 #if[intOrLong]
 836     $fpvectortype$ toFP() {
 837         $type$[] vec = getElements();
 838         $fptype$[] res = new $fptype$[this.species().length()];
 839         for(int i = 0; i < this.species().length(); i++){
 840             res[i] = $Boxfptype$.$bitstype$BitsTo$Fptype$(vec[i]);
 841         }
 842         return new $fpvectortype$(res);
 843     }
 844 #end[intOrLong]
 845 
 846     @Override
 847     public $vectortype$ rotateEL(int j) {
 848         $type$[] vec = getElements();
 849         $type$[] res = new $type$[length()];
 850         for (int i = 0; i < length(); i++){
 851             res[(j + i) % length()] = vec[i];
 852         }
 853         return new $vectortype$(res);
 854     }
 855 
 856     @Override
 857     public $vectortype$ rotateER(int j) {
 858         $type$[] vec = getElements();
 859         $type$[] res = new $type$[length()];
 860         for (int i = 0; i < length(); i++){
 861             int z = i - j;
 862             if(j < 0) {
 863                 res[length() + z] = vec[i];
 864             } else {
 865                 res[z] = vec[i];
 866             }
 867         }
 868         return new $vectortype$(res);
 869     }
 870 
 871     @Override
 872     public $vectortype$ shiftEL(int j) {
 873         $type$[] vec = getElements();
 874         $type$[] res = new $type$[length()];
 875         for (int i = 0; i < length() - j; i++) {
 876             res[i] = vec[i + j];
 877         }
 878         return new $vectortype$(res);
 879     }
 880 
 881     @Override
 882     public $vectortype$ shiftER(int j) {
 883         $type$[] vec = getElements();
 884         $type$[] res = new $type$[length()];
 885         for (int i = 0; i < length() - j; i++){
 886             res[i + j] = vec[i];
 887         }
 888         return new $vectortype$(res);
 889     }
 890 
 891     @Override
 892     public $vectortype$ shuffle(Vector<$Boxtype$, Shapes.$shape$> o, Shuffle<$Boxtype$, Shapes.$shape$> s) {
 893         $vectortype$ v = ($vectortype$) o;
 894         return uOp((i, a) -> {
 895             $type$[] vec = this.getElements();
 896             int e = s.getElement(i);
 897             if(e >= 0 && e < length()) {
 898                 //from this
 899                 return vec[e];
 900             } else if(e < length() * 2) {
 901                 //from o
 902                 return v.getElements()[e - length()];
 903             } else {
 904                 throw new ArrayIndexOutOfBoundsException("Bad reordering for shuffle");
 905             }
 906         });
 907     }
 908 
 909     @Override
 910     public $vectortype$ swizzle(Shuffle<$Boxtype$, Shapes.$shape$> s) {
 911         return uOp((i, a) -> {
 912             $type$[] vec = this.getElements();
 913             int e = s.getElement(i);
 914             if(e >= 0 && e < length()) {
 915                 return vec[e];
 916             } else {
 917                 throw new ArrayIndexOutOfBoundsException("Bad reordering for shuffle");
 918             }
 919         });
 920     }
 921 
 922     @Override
 923     @ForceInline
 924     public $vectortype$ blend(Vector<$Boxtype$, Shapes.$shape$> o1, Mask<$Boxtype$, Shapes.$shape$> o2) {
 925         Objects.requireNonNull(o1);
 926         Objects.requireNonNull(o2);
 927         $vectortype$ v = ($vectortype$)o1;
 928         $masktype$   m = ($masktype$)o2;
 929 
 930         return ($vectortype$) VectorIntrinsics.blend(
 931             $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
 932             this, v, m,
 933             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
 934     }
 935 
 936     // Accessors
 937 
 938     @Override
 939     public $type$ get(int i) {
 940         $type$[] vec = getElements();
 941         return vec[i];
 942     }
 943 
 944     @Override
 945     public $vectortype$ with(int i, $type$ e) {
 946         $type$[] res = vec.clone();
 947         res[i] = e;
 948         return new $vectortype$(res);
 949     }
 950 
 951     // Mask
 952 
 953     static final class $masktype$ extends AbstractMask<$Boxtype$, Shapes.$shape$> {
 954         static final $masktype$ TRUE_MASK = new $masktype$(true);
 955         static final $masktype$ FALSE_MASK = new $masktype$(false);
 956 
 957         // FIXME: was temporarily put here to simplify rematerialization support in the JVM
 958         private final boolean[] bits; // Don't access directly, use getBits() instead.
 959 
 960         public $masktype$(boolean[] bits) {
 961             this(bits, 0);
 962         }
 963 
 964         public $masktype$(boolean[] bits, int i) {
 965             this.bits = Arrays.copyOfRange(bits, i, i + species().length());
 966         }
 967 
 968         public $masktype$(boolean val) {
 969             boolean[] bits = new boolean[species().length()];
 970             Arrays.fill(bits, val);
 971             this.bits = bits;
 972         }
 973 
 974         boolean[] getBits() {
 975             return VectorIntrinsics.maybeRebox(this).bits;
 976         }
 977 
 978         @Override
 979         $masktype$ uOp(MUnOp f) {
 980             boolean[] res = new boolean[species().length()];
 981             boolean[] bits = getBits();
 982             for (int i = 0; i < species().length(); i++) {
 983                 res[i] = f.apply(i, bits[i]);
 984             }
 985             return new $masktype$(res);
 986         }
 987 
 988         @Override
 989         $masktype$ bOp(Mask<$Boxtype$, Shapes.$shape$> o, MBinOp f) {
 990             boolean[] res = new boolean[species().length()];
 991             boolean[] bits = getBits();
 992             boolean[] mbits = (($masktype$)o).getBits();
 993             for (int i = 0; i < species().length(); i++) {
 994                 res[i] = f.apply(i, bits[i], mbits[i]);
 995             }
 996             return new $masktype$(res);
 997         }
 998 
 999         @Override
1000         public $Type$$bits$Species species() {
1001             return SPECIES;
1002         }
1003 
1004         @Override
1005         public $vectortype$ toVector() {
1006             $type$[] res = new $type$[species().length()];
1007             boolean[] bits = getBits();
1008             for (int i = 0; i < species().length(); i++) {
1009                 res[i] = ($type$) (bits[i] ? -1 : 0);
1010             }
1011             return new $vectortype$(res);
1012         }
1013 
1014         @Override
1015         @ForceInline
1016         @SuppressWarnings("unchecked")
1017         public <Z> Mask<Z, Shapes.$shape$> rebracket(Species<Z, Shapes.$shape$> species) {
1018             Objects.requireNonNull(species);
1019             // TODO: check proper element type
1020             return VectorIntrinsics.reinterpret(
1021                 $masktype$.class, $type$.class, LENGTH,
1022                 species.elementType(), species.length(), this,
1023                 (m, t) -> m.reshape(species)
1024             );
1025         }
1026 
1027         // Unary operations
1028 
1029         //Mask<E, S> not();
1030 
1031         // Binary operations
1032 
1033         @Override
1034         @ForceInline
1035         public $masktype$ and(Mask<$Boxtype$,Shapes.$shape$> o) {
1036             Objects.requireNonNull(o);
1037             $masktype$ m = ($masktype$)o;
1038             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1039                                              this, m,
1040                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1041         }
1042 
1043         @Override
1044         @ForceInline
1045         public $masktype$ or(Mask<$Boxtype$,Shapes.$shape$> o) {
1046             Objects.requireNonNull(o);
1047             $masktype$ m = ($masktype$)o;
1048             return VectorIntrinsics.binaryOp(VECTOR_OP_OR, $masktype$.class, $bitstype$.class, LENGTH,
1049                                              this, m,
1050                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1051         }
1052 
1053         // Reductions
1054 
1055         @Override
1056         @ForceInline
1057         public boolean anyTrue() {
1058             return VectorIntrinsics.test(COND_notZero, $masktype$.class, $bitstype$.class, LENGTH,
1059                                          this, this,
1060                                          (m1, m2) -> super.anyTrue());
1061         }
1062 
1063         @Override
1064         @ForceInline
1065         public boolean allTrue() {
1066             return VectorIntrinsics.test(COND_carrySet, $masktype$.class, $bitstype$.class, LENGTH,
1067                                          this, species().maskAllTrue(),
1068                                          (m1, m2) -> super.allTrue());
1069         }
1070     }
1071 
1072     // Shuffle
1073 
1074     static final class $shuffletype$ extends AbstractShuffle<$Boxtype$, Shapes.$shape$> {
1075         static final IntVector.IntSpecies<Shapes.$shape$> INT_SPECIES = IntVector.speciesInstance(Shapes.$Shape$);
1076 
1077         public $shuffletype$(int[] reorder) {
1078             super(reorder);
1079         }
1080 
1081         public $shuffletype$(int[] reorder, int i) {
1082             super(reorder, i);
1083         }
1084 
1085         @Override
1086         public $Type$$bits$Species species() {
1087             return SPECIES;
1088         }
1089 
1090         @Override
1091         public IntVector.IntSpecies<Shapes.$shape$> intSpecies() {
1092             return INT_SPECIES;
1093         }
1094     }
1095 
1096     // Species
1097 
1098     @Override
1099     public $Type$$bits$Species species() {
1100         return SPECIES;
1101     }
1102 
1103     static final class $Type$$bits$Species extends $Type$Species<Shapes.$shape$> {
1104         static final int BIT_SIZE = Shapes.$Shape$.bitSize();
1105 
1106         static final int LENGTH = BIT_SIZE / $Boxtype$.SIZE;
1107 
1108         @Override
1109         public String toString() {
1110            StringBuilder sb = new StringBuilder("Shape[");
1111            sb.append(bitSize()).append(" bits, ");
1112            sb.append(length()).append(" ").append($type$.class.getSimpleName()).append("s x ");
1113            sb.append(elementSize()).append(" bits");
1114            sb.append("]");
1115            return sb.toString();
1116         }
1117 
1118         @Override
1119         @ForceInline
1120         public int bitSize() {
1121             return BIT_SIZE;
1122         }
1123 
1124         @Override
1125         @ForceInline
1126         public int length() {
1127             return LENGTH;
1128         }
1129 
1130         @Override
1131         @ForceInline
1132         public Class<$Boxtype$> elementType() {
1133             return $type$.class;
1134         }
1135 
1136         @Override
1137         @ForceInline
1138         public int elementSize() {
1139             return $Boxtype$.SIZE;
1140         }
1141 
1142         @Override
1143         @ForceInline
1144         public Shapes.$shape$ shape() {
1145             return Shapes.$Shape$;
1146         }
1147 
1148         @Override
1149         $vectortype$ op(FOp f) {
1150             $type$[] res = new $type$[length()];
1151             for (int i = 0; i < length(); i++) {
1152                 res[i] = f.apply(i);
1153             }
1154             return new $vectortype$(res);
1155         }
1156 
1157         @Override
1158         $vectortype$ op(Mask<$Boxtype$, Shapes.$shape$> o, FOp f) {
1159             $type$[] res = new $type$[length()];
1160             boolean[] mbits = (($masktype$)o).getBits();
1161             for (int i = 0; i < length(); i++) {
1162                 if (mbits[i]) {
1163                     res[i] = f.apply(i);
1164                 }
1165             }
1166             return new $vectortype$(res);
1167         }
1168 
1169         // Factories
1170 
1171         @Override
1172         public $masktype$ maskFromValues(boolean... bits) {
1173             return new $masktype$(bits);
1174         }
1175 
1176         @Override
1177         public $masktype$ maskFromArray(boolean[] bits, int i) {
1178             return new $masktype$(bits, i);
1179         }
1180 
1181         @Override
1182         public $shuffletype$ shuffleFromValues(int... ixs) {
1183             return new $shuffletype$(ixs);
1184         }
1185 
1186         @Override
1187         public $shuffletype$ shuffleFromArray(int[] ixs, int i) {
1188             return new $shuffletype$(ixs, i);
1189         }
1190 
1191         @Override
1192         public $shuffletype$ shuffleFromVector(Vector<Integer, Shapes.$shape$> v) {
1193             int[] a = ((IntVector<Shapes.$shape$>) v).toArray();
1194             return new $shuffletype$(a, 0);
1195         }
1196 
1197 #if[FP]
1198         @Override
1199         @ForceInline
1200         public $vectortype$ zero() {
1201             return VectorIntrinsics.broadcastCoerced($vectortype$.class, $type$.class, LENGTH,
1202                                                      $Type$.$type$To$Bitstype$Bits(0.0f),
1203                                                      (z -> ZERO));
1204         }
1205 
1206         @Override
1207         @ForceInline
1208         public $vectortype$ broadcast($type$ e) {
1209             return VectorIntrinsics.broadcastCoerced(
1210                 $vectortype$.class, $type$.class, LENGTH,
1211                 $Type$.$type$To$Bitstype$Bits(e),
1212                 ((long bits) -> SPECIES.op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
1213         }
1214 #end[FP]
1215 #if[BITWISE]
1216         @Override
1217         @ForceInline
1218         public $vectortype$ zero() {
1219             return VectorIntrinsics.broadcastCoerced($vectortype$.class, $type$.class, LENGTH,
1220                                                      0,
1221                                                      (z -> ZERO));
1222         }
1223 
1224         @Override
1225         @ForceInline
1226         public $vectortype$ broadcast($type$ e) {
1227             return VectorIntrinsics.broadcastCoerced(
1228                 $vectortype$.class, $type$.class, LENGTH,
1229                 e,
1230                 ((long bits) -> SPECIES.op(i -> ($type$)bits)));
1231         }
1232 #end[BITWISE]
1233 
1234         @Override
1235         @ForceInline
1236         public $masktype$ maskAllTrue() {
1237             return VectorIntrinsics.broadcastCoerced($masktype$.class, $bitstype$.class, LENGTH,
1238                                                      ($bitstype$)-1,
1239                                                      (z -> $masktype$.TRUE_MASK));
1240         }
1241 
1242         @Override
1243         @ForceInline
1244         public $masktype$ maskAllFalse() {
1245             return VectorIntrinsics.broadcastCoerced($masktype$.class, $bitstype$.class, LENGTH,
1246                                                      0,
1247                                                      (z -> $masktype$.FALSE_MASK));
1248         }
1249 
1250         @Override
1251         @ForceInline
1252         public $vectortype$ fromArray($type$[] a, int ix) {
1253             Objects.requireNonNull(a);
1254             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1255             return ($vectortype$) VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1256                                                         a, ix,
1257                                                         (arr, idx) -> super.fromArray(($type$[]) arr, idx));
1258         }
1259 
1260         @Override
1261         @ForceInline
1262         public $vectortype$ fromArray($type$[] a, int ax, Mask<$Boxtype$, Shapes.$shape$> m) {
1263             return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
1264         }
1265 
1266         @Override
1267         @ForceInline
1268         @SuppressWarnings("unchecked")
1269         public <F> $vectortype$ rebracket(Vector<F, Shapes.$shape$> o) {
1270             Objects.requireNonNull(o);
1271             if (o.elementType() == byte.class) {
1272                 Byte$bits$Vector so = (Byte$bits$Vector)o;
1273                 return VectorIntrinsics.reinterpret(
1274                     Byte$bits$Vector.class, byte.class, so.length(),
1275                     $type$.class, LENGTH, so,
1276                     (v, t) -> ($vectortype$)reshape(v)
1277                 );
1278             } else if (o.elementType() == short.class) {
1279                 Short$bits$Vector so = (Short$bits$Vector)o;
1280                 return VectorIntrinsics.reinterpret(
1281                     Short$bits$Vector.class, short.class, so.length(),
1282                     $type$.class, LENGTH, so,
1283                     (v, t) -> ($vectortype$)reshape(v)
1284                 );
1285             } else if (o.elementType() == int.class) {
1286                 Int$bits$Vector so = (Int$bits$Vector)o;
1287                 return VectorIntrinsics.reinterpret(
1288                     Int$bits$Vector.class, int.class, so.length(),
1289                     $type$.class, LENGTH, so,
1290                     (v, t) -> ($vectortype$)reshape(v)
1291                 );
1292             } else if (o.elementType() == long.class) {
1293                 Long$bits$Vector so = (Long$bits$Vector)o;
1294                 return VectorIntrinsics.reinterpret(
1295                     Long$bits$Vector.class, long.class, so.length(),
1296                     $type$.class, LENGTH, so,
1297                     (v, t) -> ($vectortype$)reshape(v)
1298                 );
1299             } else if (o.elementType() == float.class) {
1300                 Float$bits$Vector so = (Float$bits$Vector)o;
1301                 return VectorIntrinsics.reinterpret(
1302                     Float$bits$Vector.class, float.class, so.length(),
1303                     $type$.class, LENGTH, so,
1304                     (v, t) -> ($vectortype$)reshape(v)
1305                 );
1306             } else if (o.elementType() == double.class) {
1307                 Double$bits$Vector so = (Double$bits$Vector)o;
1308                 return VectorIntrinsics.reinterpret(
1309                     Double$bits$Vector.class, double.class, so.length(),
1310                     $type$.class, LENGTH, so,
1311                     (v, t) -> ($vectortype$)reshape(v)
1312                 );
1313             } else {
1314                 throw new InternalError("Unimplemented size");
1315             }
1316         }
1317 
1318         @Override
1319         @ForceInline
1320         @SuppressWarnings("unchecked")
1321         public <T extends Shape> $vectortype$ resize(Vector<$Boxtype$, T> o) {
1322             Objects.requireNonNull(o);
1323             if (o.bitSize() == 64) {
1324                 $Type$64Vector so = ($Type$64Vector)o;
1325                 return VectorIntrinsics.reinterpret(
1326                     $Type$64Vector.class, $type$.class, so.length(),
1327                     $type$.class, LENGTH, so,
1328                     (v, t) -> ($vectortype$)reshape(v)
1329                 );
1330             } else if (o.bitSize() == 128) {
1331                 $Type$128Vector so = ($Type$128Vector)o;
1332                 return VectorIntrinsics.reinterpret(
1333                     $Type$128Vector.class, $type$.class, so.length(),
1334                     $type$.class, LENGTH, so,
1335                     (v, t) -> ($vectortype$)reshape(v)
1336                 );
1337             } else if (o.bitSize() == 256) {
1338                 $Type$256Vector so = ($Type$256Vector)o;
1339                 return VectorIntrinsics.reinterpret(
1340                     $Type$256Vector.class, $type$.class, so.length(),
1341                     $type$.class, LENGTH, so,
1342                     (v, t) -> ($vectortype$)reshape(v)
1343                 );
1344             } else if (o.bitSize() == 512) {
1345                 $Type$512Vector so = ($Type$512Vector)o;
1346                 return VectorIntrinsics.reinterpret(
1347                     $Type$512Vector.class, $type$.class, so.length(),
1348                     $type$.class, LENGTH, so,
1349                     (v, t) -> ($vectortype$)reshape(v)
1350                 );
1351             } else {
1352                 throw new InternalError("Unimplemented size");
1353             }
1354         }
1355     }
1356 }