< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template

Print this page
rev 55589 : Species-phase2
rev 55591 : XxxSpecies made package private
rev 55592 : Capitalized Species names


  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$ {
  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 #if[!byteOrShort]
  50     // Index vector species
  51     private static final IntVector.IntSpecies INDEX_SPEC;

  52     static {
  53 #if[longOrDouble64]
  54         INDEX_SPEC = (IntVector.IntSpecies) Species.of(int.class, Shape.S_64_BIT);
  55 #else[longOrDouble64]
  56         int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
  57         Vector.Shape shape = Shape.forBitSize(bitSize);
  58         INDEX_SPEC = (IntVector.IntSpecies) Species.of(int.class, shape);
  59 #end[longOrDouble64]
  60     }

  61 #end[!byteOrShort]
  62     private final $type$[] vec; // Don't access directly, use getElements() instead.
  63 
  64     private $type$[] getElements() {
  65         return VectorIntrinsics.maybeRebox(this).vec;
  66     }
  67 
  68     $vectortype$() {
  69         vec = new $type$[SPECIES.length()];
  70     }
  71 
  72     $vectortype$($type$[] v) {
  73         vec = v;
  74     }
  75 
  76     @Override
  77     public int length() { return LENGTH; }
  78 
  79     // Unary operator
  80 


 153 
 154     @Override
 155     $type$ rOp($type$ v, FBinOp f) {
 156         $type$[] vec = getElements();
 157         for (int i = 0; i < length(); i++) {
 158             v = f.apply(i, v, vec[i]);
 159         }
 160         return v;
 161     }
 162 
 163     @Override
 164     @ForceInline
 165     public <F> Vector<F> cast(Species<F> s) {
 166         Objects.requireNonNull(s);
 167         if (s.length() != LENGTH)
 168             throw new IllegalArgumentException("Vector length this species length differ");
 169 
 170         return VectorIntrinsics.cast(
 171             $vectortype$.class,
 172             $type$.class, LENGTH,
 173             s.vectorType(),
 174             s.elementType(), LENGTH,
 175             this, s,
 176             (species, vector) -> vector.castDefault(species)
 177         );
 178     }
 179 
 180     @SuppressWarnings("unchecked")
 181     @ForceInline
 182     private <F> Vector<F> castDefault(Species<F> s) {
 183         int limit = s.length();
 184 
 185         Class<?> stype = s.elementType();
 186         if (stype == byte.class) {
 187             byte[] a = new byte[limit];
 188             for (int i = 0; i < limit; i++) {
 189                 a[i] = (byte) this.get(i);
 190             }
 191             return (Vector) ByteVector.fromArray((ByteVector.ByteSpecies) s, a, 0);
 192         } else if (stype == short.class) {
 193             short[] a = new short[limit];
 194             for (int i = 0; i < limit; i++) {
 195                 a[i] = (short) this.get(i);
 196             }
 197             return (Vector) ShortVector.fromArray((ShortVector.ShortSpecies) s, a, 0);
 198         } else if (stype == int.class) {
 199             int[] a = new int[limit];
 200             for (int i = 0; i < limit; i++) {
 201                 a[i] = (int) this.get(i);
 202             }
 203             return (Vector) IntVector.fromArray((IntVector.IntSpecies) s, a, 0);
 204         } else if (stype == long.class) {
 205             long[] a = new long[limit];
 206             for (int i = 0; i < limit; i++) {
 207                 a[i] = (long) this.get(i);
 208             }
 209             return (Vector) LongVector.fromArray((LongVector.LongSpecies) s, a, 0);
 210         } else if (stype == float.class) {
 211             float[] a = new float[limit];
 212             for (int i = 0; i < limit; i++) {
 213                 a[i] = (float) this.get(i);
 214             }
 215             return (Vector) FloatVector.fromArray((FloatVector.FloatSpecies) s, a, 0);
 216         } else if (stype == double.class) {
 217             double[] a = new double[limit];
 218             for (int i = 0; i < limit; i++) {
 219                 a[i] = (double) this.get(i);
 220             }
 221             return (Vector) DoubleVector.fromArray((DoubleVector.DoubleSpecies) s, a, 0);
 222         } else {
 223             throw new UnsupportedOperationException("Bad lane type for casting.");
 224         }
 225     }
 226 
 227     @Override
 228     @ForceInline
 229     @SuppressWarnings("unchecked")
 230     public <F> Vector<F> reinterpret(Species<F> s) {
 231         Objects.requireNonNull(s);
 232 
 233         if(s.elementType().equals($type$.class)) {
 234             return (Vector<F>) reshape((Species<$Boxtype$>)s);
 235         }
 236         if(s.bitSize() == bitSize()) {
 237             return reinterpretType(s);
 238         }
 239 
 240         return defaultReinterpret(s);
 241     }


 291                 (species, vector) -> vector.defaultReinterpret(species)
 292             );
 293         } else if (stype == double.class) {
 294             return VectorIntrinsics.reinterpret(
 295                 $vectortype$.class,
 296                 $type$.class, LENGTH,
 297                 Double$bits$Vector.class,
 298                 double.class, Double$bits$Vector.LENGTH,
 299                 this, s,
 300                 (species, vector) -> vector.defaultReinterpret(species)
 301             );
 302         } else {
 303             throw new UnsupportedOperationException("Bad lane type for casting.");
 304         }
 305     }
 306 
 307     @Override
 308     @ForceInline
 309     public $abstractvectortype$ reshape(Species<$Boxtype$> s) {
 310         Objects.requireNonNull(s);
 311         if (s.bitSize() == 64 && (s instanceof $Type$64Vector.$Type$64Species)) {
 312             $Type$64Vector.$Type$64Species ts = ($Type$64Vector.$Type$64Species)s;
 313             return VectorIntrinsics.reinterpret(
 314                 $vectortype$.class,
 315                 $type$.class, LENGTH,
 316                 $Type$64Vector.class,
 317                 $type$.class, $Type$64Vector.LENGTH,
 318                 this, ts,
 319                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 320             );
 321         } else if (s.bitSize() == 128 && (s instanceof $Type$128Vector.$Type$128Species)) {
 322             $Type$128Vector.$Type$128Species ts = ($Type$128Vector.$Type$128Species)s;
 323             return VectorIntrinsics.reinterpret(
 324                 $vectortype$.class,
 325                 $type$.class, LENGTH,
 326                 $Type$128Vector.class,
 327                 $type$.class, $Type$128Vector.LENGTH,
 328                 this, ts,
 329                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 330             );
 331         } else if (s.bitSize() == 256 && (s instanceof $Type$256Vector.$Type$256Species)) {
 332             $Type$256Vector.$Type$256Species ts = ($Type$256Vector.$Type$256Species)s;
 333             return VectorIntrinsics.reinterpret(
 334                 $vectortype$.class,
 335                 $type$.class, LENGTH,
 336                 $Type$256Vector.class,
 337                 $type$.class, $Type$256Vector.LENGTH,
 338                 this, ts,
 339                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 340             );
 341         } else if (s.bitSize() == 512 && (s instanceof $Type$512Vector.$Type$512Species)) {
 342             $Type$512Vector.$Type$512Species ts = ($Type$512Vector.$Type$512Species)s;
 343             return VectorIntrinsics.reinterpret(
 344                 $vectortype$.class,
 345                 $type$.class, LENGTH,
 346                 $Type$512Vector.class,
 347                 $type$.class, $Type$512Vector.LENGTH,
 348                 this, ts,
 349                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 350             );
 351         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 352                 && (s.bitSize() % 128 == 0) && (s instanceof $Type$MaxVector.$Type$MaxSpecies)) {
 353             $Type$MaxVector.$Type$MaxSpecies ts = ($Type$MaxVector.$Type$MaxSpecies)s;
 354             return VectorIntrinsics.reinterpret(
 355                 $vectortype$.class,
 356                 $type$.class, LENGTH,
 357                 $Type$MaxVector.class,
 358                 $type$.class, $Type$MaxVector.LENGTH,
 359                 this, ts,
 360                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 361             );
 362         } else {
 363             throw new InternalError("Unimplemented size");
 364         }
 365     }
 366 
 367     // Binary operations with scalars
 368 
 369     @Override
 370     @ForceInline
 371     public $abstractvectortype$ add($type$ o) {
 372         return add(SPECIES.broadcast(o));
 373     }
 374 
 375     @Override
 376     @ForceInline
 377     public $abstractvectortype$ add($type$ o, Mask<$Boxtype$> m) {
 378         return add(SPECIES.broadcast(o), m);
 379     }
 380 
 381     @Override
 382     @ForceInline
 383     public $abstractvectortype$ sub($type$ o) {
 384         return sub(SPECIES.broadcast(o));
 385     }
 386 
 387     @Override
 388     @ForceInline
 389     public $abstractvectortype$ sub($type$ o, Mask<$Boxtype$> m) {
 390         return sub(SPECIES.broadcast(o), m);
 391     }
 392 
 393     @Override
 394     @ForceInline
 395     public $abstractvectortype$ mul($type$ o) {
 396         return mul(SPECIES.broadcast(o));
 397     }
 398 
 399     @Override
 400     @ForceInline
 401     public $abstractvectortype$ mul($type$ o, Mask<$Boxtype$> m) {
 402         return mul(SPECIES.broadcast(o), m);
 403     }
 404 
 405     @Override
 406     @ForceInline
 407     public $abstractvectortype$ min($type$ o) {
 408         return min(SPECIES.broadcast(o));
 409     }
 410 
 411     @Override
 412     @ForceInline
 413     public $abstractvectortype$ max($type$ o) {
 414         return max(SPECIES.broadcast(o));
 415     }
 416 
 417     @Override
 418     @ForceInline
 419     public Mask<$Boxtype$> equal($type$ o) {
 420         return equal(SPECIES.broadcast(o));
 421     }
 422 
 423     @Override
 424     @ForceInline
 425     public Mask<$Boxtype$> notEqual($type$ o) {
 426         return notEqual(SPECIES.broadcast(o));
 427     }
 428 
 429     @Override
 430     @ForceInline
 431     public Mask<$Boxtype$> lessThan($type$ o) {
 432         return lessThan(SPECIES.broadcast(o));
 433     }
 434 
 435     @Override
 436     @ForceInline
 437     public Mask<$Boxtype$> lessThanEq($type$ o) {
 438         return lessThanEq(SPECIES.broadcast(o));
 439     }
 440 
 441     @Override
 442     @ForceInline
 443     public Mask<$Boxtype$> greaterThan($type$ o) {
 444         return greaterThan(SPECIES.broadcast(o));
 445     }
 446 
 447     @Override
 448     @ForceInline
 449     public Mask<$Boxtype$> greaterThanEq($type$ o) {
 450         return greaterThanEq(SPECIES.broadcast(o));
 451     }
 452 
 453     @Override
 454     @ForceInline
 455     public $abstractvectortype$ blend($type$ o, Mask<$Boxtype$> m) {
 456         return blend(SPECIES.broadcast(o), m);
 457     }
 458 
 459 #if[FP]
 460     @Override
 461     @ForceInline
 462     public $abstractvectortype$ div($type$ o) {
 463         return div(SPECIES.broadcast(o));
 464     }
 465 
 466     @Override
 467     @ForceInline
 468     public $abstractvectortype$ div($type$ o, Mask<$Boxtype$> m) {
 469         return div(SPECIES.broadcast(o), m);
 470     }
 471 
 472     @Override
 473     @ForceInline
 474     public $vectortype$ div(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
 475         return blend(div(v), m);
 476     }
 477 
 478     @Override
 479     @ForceInline
 480     public $abstractvectortype$ atan2($type$ o) {
 481         return atan2(SPECIES.broadcast(o));
 482     }
 483 
 484     @Override
 485     @ForceInline
 486     public $abstractvectortype$ atan2($type$ o, Mask<$Boxtype$> m) {
 487         return atan2(SPECIES.broadcast(o), m);
 488     }
 489 
 490     @Override
 491     @ForceInline
 492     public $abstractvectortype$ pow($type$ o) {
 493         return pow(SPECIES.broadcast(o));
 494     }
 495 
 496     @Override
 497     @ForceInline
 498     public $abstractvectortype$ pow($type$ o, Mask<$Boxtype$> m) {
 499         return pow(SPECIES.broadcast(o), m);
 500     }
 501 
 502     @Override
 503     @ForceInline
 504     public $abstractvectortype$ fma($type$ o1, $type$ o2) {
 505         return fma(SPECIES.broadcast(o1), SPECIES.broadcast(o2));
 506     }
 507 
 508     @Override
 509     @ForceInline
 510     public $abstractvectortype$ fma($type$ o1, $type$ o2, Mask<$Boxtype$> m) {
 511         return fma(SPECIES.broadcast(o1), SPECIES.broadcast(o2), m);
 512     }
 513 
 514     @Override
 515     @ForceInline
 516     public $abstractvectortype$ hypot($type$ o) {
 517         return hypot(SPECIES.broadcast(o));
 518     }
 519 
 520     @Override
 521     @ForceInline
 522     public $abstractvectortype$ hypot($type$ o, Mask<$Boxtype$> m) {
 523         return hypot(SPECIES.broadcast(o), m);
 524     }
 525 #end[FP]
 526 
 527 #if[BITWISE]
 528     @Override
 529     @ForceInline
 530     public $abstractvectortype$ and($type$ o) {
 531         return and(SPECIES.broadcast(o));
 532     }
 533 
 534     @Override
 535     @ForceInline
 536     public $abstractvectortype$ and($type$ o, Mask<$Boxtype$> m) {
 537         return and(SPECIES.broadcast(o), m);
 538     }
 539 
 540     @Override
 541     @ForceInline
 542     public $abstractvectortype$ or($type$ o) {
 543         return or(SPECIES.broadcast(o));
 544     }
 545 
 546     @Override
 547     @ForceInline
 548     public $abstractvectortype$ or($type$ o, Mask<$Boxtype$> m) {
 549         return or(SPECIES.broadcast(o), m);
 550     }
 551 
 552     @Override
 553     @ForceInline
 554     public $abstractvectortype$ xor($type$ o) {
 555         return xor(SPECIES.broadcast(o));
 556     }
 557 
 558     @Override
 559     @ForceInline
 560     public $abstractvectortype$ xor($type$ o, Mask<$Boxtype$> m) {
 561         return xor(SPECIES.broadcast(o), m);
 562     }
 563 
 564     @Override
 565     @ForceInline
 566     public $vectortype$ neg() {
 567         return ($vectortype$)zero(SPECIES).sub(this);
 568     }
 569 #end[BITWISE]
 570 
 571     // Unary operations
 572 
 573     @ForceInline
 574     @Override
 575     public $vectortype$ neg(Mask<$Boxtype$> m) {
 576         return blend(neg(), m);
 577     }
 578 
 579     @Override
 580     @ForceInline
 581     public $vectortype$ abs() {


1073     @Override
1074     @ForceInline
1075     public $vectortype$ aShiftR(int s) {
1076         return VectorIntrinsics.broadcastInt(
1077             VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1078             this, s,
1079             (v, i) -> v.uOp((__, a) -> ($type$) (a >> i)));
1080     }
1081 
1082     @Override
1083     @ForceInline
1084     public $vectortype$ aShiftR(int s, Mask<$Boxtype$> m) {
1085         return blend(aShiftR(s), m);
1086     }
1087 
1088     @Override
1089     @ForceInline
1090     public $vectortype$ shiftL(Vector<$Boxtype$> s) {
1091         $vectortype$ shiftv = ($vectortype$)s;
1092         // As per shift specification for Java, mask the shift count.
1093         shiftv = shiftv.and(species().broadcast({#if[int]?0x1f:0x3f}));
1094         return VectorIntrinsics.binaryOp(
1095             VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
1096             this, shiftv,
1097             (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a << b)));
1098     }
1099 
1100     @Override
1101     @ForceInline
1102     public $vectortype$ shiftR(Vector<$Boxtype$> s) {
1103         $vectortype$ shiftv = ($vectortype$)s;
1104         // As per shift specification for Java, mask the shift count.
1105         shiftv = shiftv.and(species().broadcast({#if[int]?0x1f:0x3f}));
1106         return VectorIntrinsics.binaryOp(
1107             VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
1108             this, shiftv,
1109             (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a >>> b)));
1110     }
1111 
1112     @Override
1113     @ForceInline
1114     public $vectortype$ aShiftR(Vector<$Boxtype$> s) {
1115         $vectortype$ shiftv = ($vectortype$)s;
1116         // As per shift specification for Java, mask the shift count.
1117         shiftv = shiftv.and(species().broadcast({#if[int]?0x1f:0x3f}));
1118         return VectorIntrinsics.binaryOp(
1119             VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1120             this, shiftv,
1121             (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a >> b)));
1122     }
1123 #end[intOrLong]
1124     // Ternary operations
1125 
1126 #if[FP]
1127     @Override
1128     @ForceInline
1129     public $vectortype$ fma(Vector<$Boxtype$> o1, Vector<$Boxtype$> o2) {
1130         Objects.requireNonNull(o1);
1131         Objects.requireNonNull(o2);
1132         $vectortype$ v1 = ($vectortype$)o1;
1133         $vectortype$ v2 = ($vectortype$)o2;
1134         return VectorIntrinsics.ternaryOp(
1135             VECTOR_OP_FMA, $vectortype$.class, $type$.class, LENGTH,
1136             this, v1, v2,
1137             (w1, w2, w3) -> w1.tOp(w2, w3, (i, a, b, c) -> Math.fma(a, b, c)));


1145     @ForceInline
1146     public $type$ addAll() {
1147         return ($type$) VectorIntrinsics.reductionCoerced(
1148             VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1149             this,
1150             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b)));
1151     }
1152 
1153     @Override
1154     @ForceInline
1155     public $type$ andAll() {
1156         return ($type$) VectorIntrinsics.reductionCoerced(
1157             VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
1158             this,
1159             v -> (long) v.rOp(($type$) -1, (i, a, b) -> ($type$) (a & b)));
1160     }
1161 
1162     @Override
1163     @ForceInline
1164     public $type$ andAll(Mask<$Boxtype$> m) {
1165         return SPECIES.broadcast(($type$) -1).blend(this, m).andAll();
1166     }
1167 
1168     @Override
1169     @ForceInline
1170     public $type$ minAll() {
1171         return ($type$) VectorIntrinsics.reductionCoerced(
1172             VECTOR_OP_MIN, $vectortype$.class, $type$.class, LENGTH,
1173             this,
1174             v -> (long) v.rOp($Boxtype$.MAX_VALUE , (i, a, b) -> ($type$) Math.min(a, b)));
1175     }
1176 
1177     @Override
1178     @ForceInline
1179     public $type$ maxAll() {
1180         return ($type$) VectorIntrinsics.reductionCoerced(
1181             VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1182             this,
1183             v -> (long) v.rOp($Boxtype$.MIN_VALUE , (i, a, b) -> ($type$) Math.max(a, b)));
1184     }
1185 


1187     @ForceInline
1188     public $type$ mulAll() {
1189         return ($type$) VectorIntrinsics.reductionCoerced(
1190             VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
1191             this,
1192             v -> (long) v.rOp(($type$) 1, (i, a, b) -> ($type$) (a * b)));
1193     }
1194 
1195     @Override
1196     @ForceInline
1197     public $type$ orAll() {
1198         return ($type$) VectorIntrinsics.reductionCoerced(
1199             VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
1200             this,
1201             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a | b)));
1202     }
1203 
1204     @Override
1205     @ForceInline
1206     public $type$ orAll(Mask<$Boxtype$> m) {
1207         return SPECIES.broadcast(($type$) 0).blend(this, m).orAll();
1208     }
1209 
1210     @Override
1211     @ForceInline
1212     public $type$ xorAll() {
1213         return ($type$) VectorIntrinsics.reductionCoerced(
1214             VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
1215             this,
1216             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a ^ b)));
1217     }
1218 
1219     @Override
1220     @ForceInline
1221     public $type$ xorAll(Mask<$Boxtype$> m) {
1222         return SPECIES.broadcast(($type$) 0).blend(this, m).xorAll();
1223     }
1224 #end[BITWISE]
1225 
1226 #if[FP]
1227     @Override
1228     @ForceInline
1229     public $type$ addAll() {
1230         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1231                                 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1232                                 this,
1233                                 v -> {
1234                                     $type$ r = v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b));
1235                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
1236                                 });
1237         return $Type$.$bitstype$BitsTo$Fptype$(bits);
1238     }
1239 
1240     @Override
1241     @ForceInline
1242     public $type$ mulAll() {


1264     }
1265 
1266     @Override
1267     @ForceInline
1268     public $type$ maxAll() {
1269         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1270                                 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1271                                 this,
1272                                 v -> {
1273                                     $type$ r = v.rOp($Boxtype$.MIN_VALUE , (i, a, b) -> ($type$) Math.max(a, b));
1274                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
1275                                 });
1276         return $Type$.$bitstype$BitsTo$Fptype$(bits);
1277     }
1278 
1279 #end[FP]
1280 
1281     @Override
1282     @ForceInline
1283     public $type$ addAll(Mask<$Boxtype$> m) {
1284         return SPECIES.broadcast(($type$) 0).blend(this, m).addAll();
1285     }
1286 
1287 
1288     @Override
1289     @ForceInline
1290     public $type$ mulAll(Mask<$Boxtype$> m) {
1291         return SPECIES.broadcast(($type$) 1).blend(this, m).mulAll();
1292     }
1293 
1294     @Override
1295     @ForceInline
1296     public $type$ minAll(Mask<$Boxtype$> m) {
1297         return SPECIES.broadcast($Boxtype$.MAX_VALUE).blend(this, m).minAll();
1298     }
1299 
1300     @Override
1301     @ForceInline
1302     public $type$ maxAll(Mask<$Boxtype$> m) {
1303         return SPECIES.broadcast($Boxtype$.MIN_VALUE).blend(this, m).maxAll();
1304     }
1305 
1306     @Override
1307     @ForceInline
1308     public Shuffle<$Boxtype$> toShuffle() {
1309         $type$[] a = toArray();
1310         int[] sa = new int[a.length];
1311         for (int i = 0; i < a.length; i++) {
1312             sa[i] = (int) a[i];
1313         }
1314         return $abstractvectortype$.shuffleFromArray(SPECIES, sa, 0);
1315     }
1316 
1317     // Memory operations
1318 
1319     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE);
1320     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
1321 
1322     @Override
1323     @ForceInline


1332     }
1333 
1334     @Override
1335     @ForceInline
1336     public final void intoArray($type$[] a, int ax, Mask<$Boxtype$> m) {
1337         $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax);
1338         $abstractvectortype$ newVal = oldVal.blend(this, m);
1339         newVal.intoArray(a, ax);
1340     }
1341 #if[!byteOrShort]
1342     @Override
1343     @ForceInline
1344     public void intoArray($type$[] a, int ix, int[] b, int iy) {
1345 #if[longOrDouble64]
1346         this.intoArray(a, ix + b[iy]);
1347 #else[longOrDouble64]
1348         Objects.requireNonNull(a);
1349         Objects.requireNonNull(b);
1350 
1351         // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
1352         IntVector vix = IntVector.fromArray(INDEX_SPEC, b, iy).add(ix);
1353 
1354         vix = VectorIntrinsics.checkIndex(vix, a.length);
1355 
1356         VectorIntrinsics.storeWithMap($vectortype$.class, $type$.class, LENGTH, $vectorindextype$,
1357                                a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix,
1358                                this,
1359                                a, ix, b, iy,
1360                                (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
1361 #end[longOrDouble64]
1362     }
1363 
1364      @Override
1365      @ForceInline
1366      public final void intoArray($type$[] a, int ax, Mask<$Boxtype$> m, int[] b, int iy) {
1367          // @@@ This can result in out of bounds errors for unset mask lanes
1368          $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax, b, iy);
1369          $abstractvectortype$ newVal = oldVal.blend(this, m);
1370          newVal.intoArray(a, ax, b, iy);
1371      }
1372 #end[!byteOrShort]


1751             boolean[] res = new boolean[species().length()];
1752             boolean[] bits = getBits();
1753             for (int i = 0; i < species().length(); i++) {
1754                 res[i] = f.apply(i, bits[i]);
1755             }
1756             return new $masktype$(res);
1757         }
1758 
1759         @Override
1760         $masktype$ bOp(Mask<$Boxtype$> o, MBinOp f) {
1761             boolean[] res = new boolean[species().length()];
1762             boolean[] bits = getBits();
1763             boolean[] mbits = (($masktype$)o).getBits();
1764             for (int i = 0; i < species().length(); i++) {
1765                 res[i] = f.apply(i, bits[i], mbits[i]);
1766             }
1767             return new $masktype$(res);
1768         }
1769 
1770         @Override
1771         public $Type$$bits$Species species() {
1772             return SPECIES;
1773         }
1774 
1775         @Override
1776         public $vectortype$ toVector() {
1777             $type$[] res = new $type$[species().length()];
1778             boolean[] bits = getBits();
1779             for (int i = 0; i < species().length(); i++) {
1780                 // -1 will result in the most significant bit being set in
1781                 // addition to some or all other bits
1782                 res[i] = ($type$) (bits[i] ? -1 : 0);
1783             }
1784             return new $vectortype$(res);
1785         }
1786 

























1787         // Unary operations
1788 
1789         @Override
1790         @ForceInline
1791         public $masktype$ not() {
1792             return ($masktype$) VectorIntrinsics.unaryOp(
1793                                              VECTOR_OP_NOT, $masktype$.class, $bitstype$.class, LENGTH,
1794                                              this,
1795                                              (m1) -> m1.uOp((i, a) -> !a));
1796         }
1797 
1798         // Binary operations
1799 
1800         @Override
1801         @ForceInline
1802         public $masktype$ and(Mask<$Boxtype$> o) {
1803             Objects.requireNonNull(o);
1804             $masktype$ m = ($masktype$)o;
1805             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1806                                              this, m,


1839     // Shuffle
1840 
1841     static final class $shuffletype$ extends AbstractShuffle<$Boxtype$> {
1842         $shuffletype$(byte[] reorder) {
1843             super(reorder);
1844         }
1845 
1846         public $shuffletype$(int[] reorder) {
1847             super(reorder);
1848         }
1849 
1850         public $shuffletype$(int[] reorder, int i) {
1851             super(reorder, i);
1852         }
1853 
1854         public $shuffletype$(IntUnaryOperator f) {
1855             super(f);
1856         }
1857 
1858         @Override
1859         public $Type$$bits$Species species() {
1860             return SPECIES;
1861         }
1862 
1863         @Override
1864         public $abstractvectortype$ toVector() {
1865             $type$[] va = new $type$[SPECIES.length()];
1866             for (int i = 0; i < va.length; i++) {
1867               va[i] = ($type$) getElement(i);
1868             }
1869             return $abstractvectortype$.fromArray(SPECIES, va, 0);
1870         }
1871 
1872         @Override

























1873         public $shuffletype$ rearrange(Vector.Shuffle<$Boxtype$> o) {
1874             $shuffletype$ s = ($shuffletype$) o;
1875             byte[] r = new byte[reorder.length];
1876             for (int i = 0; i < reorder.length; i++) {
1877                 r[i] = reorder[s.reorder[i]];
1878             }
1879             return new $shuffletype$(r);
1880         }
1881     }
1882 
1883     // Species
1884 
1885     @Override
1886     public $Type$$bits$Species species() {
1887         return SPECIES;
1888     }
1889 
1890     static final class $Type$$bits$Species extends $Type$Species {
1891         static final int BIT_SIZE = Shape.$Shape$.bitSize();
1892 
1893         static final int LENGTH = BIT_SIZE / $Boxtype$.SIZE;
1894 
1895         @Override
1896         public String toString() {
1897            StringBuilder sb = new StringBuilder("Shape[");
1898            sb.append(bitSize()).append(" bits, ");
1899            sb.append(length()).append(" ").append($type$.class.getSimpleName()).append("s x ");
1900            sb.append(elementSize()).append(" bits");
1901            sb.append("]");
1902            return sb.toString();
1903         }
1904 
1905         @Override
1906         @ForceInline
1907         public int bitSize() {
1908             return BIT_SIZE;
1909         }
1910 
1911         @Override
1912         @ForceInline
1913         public int length() {
1914             return LENGTH;
1915         }
1916 
1917         @Override
1918         @ForceInline
1919         public Class<$Boxtype$> elementType() {
1920             return $type$.class;
1921         }
1922 
1923         @Override
1924         @ForceInline
1925         public Class<?> boxType() {
1926             return $vectortype$.class;
1927         }
1928 
1929         @Override
1930         @ForceInline
1931         public Class<?> maskType() {
1932             return $masktype$.class;
1933         }
1934 
1935         @Override
1936         @ForceInline
1937         public int elementSize() {
1938             return $Boxtype$.SIZE;
1939         }
1940 
1941         @Override
1942         @ForceInline
1943         @SuppressWarnings("unchecked")
1944         Class<?> vectorType() {
1945             return $vectortype$.class;
1946         }
1947 
1948         @Override
1949         @ForceInline
1950         public Shape shape() {
1951             return Shape.$Shape$;
1952         }
1953 
1954 #if[!byteOrShort]
1955        @Override
1956        IntVector.IntSpecies indexSpecies() {
1957           return INDEX_SPEC;
1958        }
1959 
1960 #end[!byteOrShort]
1961         @Override
1962         $vectortype$ op(FOp f) {
1963             $type$[] res = new $type$[length()];
1964             for (int i = 0; i < length(); i++) {
1965                 res[i] = f.apply(i);
1966             }
1967             return new $vectortype$(res);
1968         }
1969 
1970         @Override
1971         $vectortype$ op(Mask<$Boxtype$> o, FOp f) {
1972             $type$[] res = new $type$[length()];
1973             boolean[] mbits = (($masktype$)o).getBits();
1974             for (int i = 0; i < length(); i++) {
1975                 if (mbits[i]) {
1976                     res[i] = f.apply(i);
1977                 }
1978             }
1979             return new $vectortype$(res);
1980         }
1981 
1982         @Override
1983         $masktype$ opm(FOpm f) {
1984             boolean[] res = new boolean[length()];
1985             for (int i = 0; i < length(); i++) {
1986                 res[i] = (boolean)f.apply(i);
1987             }
1988             return new $masktype$(res);
1989         }
1990 
1991         // Factories
1992 
1993 #if[FP]
1994         @Override
1995         @ForceInline
1996         public $vectortype$ zero() {
1997             return VectorIntrinsics.broadcastCoerced($vectortype$.class, $type$.class, LENGTH,
1998                                                      $Type$.$type$To$Bitstype$Bits(0.0f), SPECIES, 
1999                                                      ((bits, s) -> (($Type$$bits$Species)s).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
2000         }
2001 
2002         @Override
2003         @ForceInline
2004         public $vectortype$ broadcast($type$ e) {
2005             return VectorIntrinsics.broadcastCoerced(
2006                 $vectortype$.class, $type$.class, LENGTH,
2007                 $Type$.$type$To$Bitstype$Bits(e), SPECIES,
2008                 ((bits, s) -> (($Type$$bits$Species)s).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
2009         }
2010 #end[FP]
2011 #if[BITWISE]
2012         @Override
2013         @ForceInline
2014         public $vectortype$ zero() {
2015             return VectorIntrinsics.broadcastCoerced($vectortype$.class, $type$.class, LENGTH,
2016                                                      0, SPECIES,
2017                                                      ((bits, s) -> (($Type$$bits$Species)s).op(i -> ($type$)bits)));
2018         }
2019 
2020         @Override
2021         @ForceInline
2022         public $vectortype$ broadcast($type$ e) {
2023             return VectorIntrinsics.broadcastCoerced(
2024                 $vectortype$.class, $type$.class, LENGTH,
2025                 e, SPECIES,
2026                 ((bits, s) -> (($Type$$bits$Species)s).op(i -> ($type$)bits)));
2027         }
2028 #end[BITWISE]
2029 
2030         @Override
2031         @ForceInline
2032         public $vectortype$ scalars($type$... es) {
2033             Objects.requireNonNull(es);
2034             int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH);
2035             return VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
2036                                          es, Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
2037                                          es, ix, SPECIES,
2038                                          (c, idx, s) -> (($Type$$bits$Species)s).op(n -> c[idx + n]));
2039         }
2040 
2041         @Override
2042         @ForceInline
2043         public <E> $masktype$ cast(Mask<E> m) {
2044             if (m.length() != LENGTH)
2045                 throw new IllegalArgumentException("Mask length this species length differ");
2046             return new $masktype$(m.toArray());
2047         }
2048 
2049         @Override
2050         @ForceInline
2051         public <E> $shuffletype$ cast(Shuffle<E> s) {
2052             if (s.length() != LENGTH)
2053                 throw new IllegalArgumentException("Shuffle length this species length differ");
2054             return new $shuffletype$(s.toArray());
2055         }
2056     }
2057 }


  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$ {
  43     private static final Species<$Boxtype$> SPECIES = $Type$Vector.SPECIES_$BITS$;
  44 
  45     static final $vectortype$ ZERO = new $vectortype$();
  46 
  47     static final int LENGTH = SPECIES.length();
  48 
  49 #if[!byteOrShort]
  50     // Index vector species
  51     private static final IntVector.IntSpecies INDEX_SPECIES;
  52 
  53     static {
  54 #if[longOrDouble64]
  55         INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.S_64_BIT);
  56 #else[longOrDouble64]
  57         int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
  58         INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.forBitSize(bitSize));

  59 #end[longOrDouble64]
  60     }
  61 
  62 #end[!byteOrShort]
  63     private final $type$[] vec; // Don't access directly, use getElements() instead.
  64 
  65     private $type$[] getElements() {
  66         return VectorIntrinsics.maybeRebox(this).vec;
  67     }
  68 
  69     $vectortype$() {
  70         vec = new $type$[SPECIES.length()];
  71     }
  72 
  73     $vectortype$($type$[] v) {
  74         vec = v;
  75     }
  76 
  77     @Override
  78     public int length() { return LENGTH; }
  79 
  80     // Unary operator
  81 


 154 
 155     @Override
 156     $type$ rOp($type$ v, FBinOp f) {
 157         $type$[] vec = getElements();
 158         for (int i = 0; i < length(); i++) {
 159             v = f.apply(i, v, vec[i]);
 160         }
 161         return v;
 162     }
 163 
 164     @Override
 165     @ForceInline
 166     public <F> Vector<F> cast(Species<F> s) {
 167         Objects.requireNonNull(s);
 168         if (s.length() != LENGTH)
 169             throw new IllegalArgumentException("Vector length this species length differ");
 170 
 171         return VectorIntrinsics.cast(
 172             $vectortype$.class,
 173             $type$.class, LENGTH,
 174             s.boxType(),
 175             s.elementType(), LENGTH,
 176             this, s,
 177             (species, vector) -> vector.castDefault(species)
 178         );
 179     }
 180 
 181     @SuppressWarnings("unchecked")
 182     @ForceInline
 183     private <F> Vector<F> castDefault(Species<F> s) {
 184         int limit = s.length();
 185 
 186         Class<?> stype = s.elementType();
 187         if (stype == byte.class) {
 188             byte[] a = new byte[limit];
 189             for (int i = 0; i < limit; i++) {
 190                 a[i] = (byte) this.get(i);
 191             }
 192             return (Vector) ByteVector.fromArray((Species<Byte>) s, a, 0);
 193         } else if (stype == short.class) {
 194             short[] a = new short[limit];
 195             for (int i = 0; i < limit; i++) {
 196                 a[i] = (short) this.get(i);
 197             }
 198             return (Vector) ShortVector.fromArray((Species<Short>) s, a, 0);
 199         } else if (stype == int.class) {
 200             int[] a = new int[limit];
 201             for (int i = 0; i < limit; i++) {
 202                 a[i] = (int) this.get(i);
 203             }
 204             return (Vector) IntVector.fromArray((Species<Integer>) s, a, 0);
 205         } else if (stype == long.class) {
 206             long[] a = new long[limit];
 207             for (int i = 0; i < limit; i++) {
 208                 a[i] = (long) this.get(i);
 209             }
 210             return (Vector) LongVector.fromArray((Species<Long>) s, a, 0);
 211         } else if (stype == float.class) {
 212             float[] a = new float[limit];
 213             for (int i = 0; i < limit; i++) {
 214                 a[i] = (float) this.get(i);
 215             }
 216             return (Vector) FloatVector.fromArray((Species<Float>) s, a, 0);
 217         } else if (stype == double.class) {
 218             double[] a = new double[limit];
 219             for (int i = 0; i < limit; i++) {
 220                 a[i] = (double) this.get(i);
 221             }
 222             return (Vector) DoubleVector.fromArray((Species<Double>) s, a, 0);
 223         } else {
 224             throw new UnsupportedOperationException("Bad lane type for casting.");
 225         }
 226     }
 227 
 228     @Override
 229     @ForceInline
 230     @SuppressWarnings("unchecked")
 231     public <F> Vector<F> reinterpret(Species<F> s) {
 232         Objects.requireNonNull(s);
 233 
 234         if(s.elementType().equals($type$.class)) {
 235             return (Vector<F>) reshape((Species<$Boxtype$>)s);
 236         }
 237         if(s.bitSize() == bitSize()) {
 238             return reinterpretType(s);
 239         }
 240 
 241         return defaultReinterpret(s);
 242     }


 292                 (species, vector) -> vector.defaultReinterpret(species)
 293             );
 294         } else if (stype == double.class) {
 295             return VectorIntrinsics.reinterpret(
 296                 $vectortype$.class,
 297                 $type$.class, LENGTH,
 298                 Double$bits$Vector.class,
 299                 double.class, Double$bits$Vector.LENGTH,
 300                 this, s,
 301                 (species, vector) -> vector.defaultReinterpret(species)
 302             );
 303         } else {
 304             throw new UnsupportedOperationException("Bad lane type for casting.");
 305         }
 306     }
 307 
 308     @Override
 309     @ForceInline
 310     public $abstractvectortype$ reshape(Species<$Boxtype$> s) {
 311         Objects.requireNonNull(s);
 312         if (s.bitSize() == 64 && (s.boxType() == $Type$64Vector.class)) {

 313             return VectorIntrinsics.reinterpret(
 314                 $vectortype$.class,
 315                 $type$.class, LENGTH,
 316                 $Type$64Vector.class,
 317                 $type$.class, $Type$64Vector.LENGTH,
 318                 this, s,
 319                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 320             );
 321         } else if (s.bitSize() == 128 && (s.boxType() == $Type$128Vector.class)) {

 322             return VectorIntrinsics.reinterpret(
 323                 $vectortype$.class,
 324                 $type$.class, LENGTH,
 325                 $Type$128Vector.class,
 326                 $type$.class, $Type$128Vector.LENGTH,
 327                 this, s,
 328                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 329             );
 330         } else if (s.bitSize() == 256 && (s.boxType() == $Type$256Vector.class)) {

 331             return VectorIntrinsics.reinterpret(
 332                 $vectortype$.class,
 333                 $type$.class, LENGTH,
 334                 $Type$256Vector.class,
 335                 $type$.class, $Type$256Vector.LENGTH,
 336                 this, s,
 337                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 338             );
 339         } else if (s.bitSize() == 512 && (s.boxType() == $Type$512Vector.class)) {

 340             return VectorIntrinsics.reinterpret(
 341                 $vectortype$.class,
 342                 $type$.class, LENGTH,
 343                 $Type$512Vector.class,
 344                 $type$.class, $Type$512Vector.LENGTH,
 345                 this, s,
 346                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 347             );
 348         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 349                 && (s.bitSize() % 128 == 0) && (s.boxType() == $Type$MaxVector.class)) {

 350             return VectorIntrinsics.reinterpret(
 351                 $vectortype$.class,
 352                 $type$.class, LENGTH,
 353                 $Type$MaxVector.class,
 354                 $type$.class, $Type$MaxVector.LENGTH,
 355                 this, s,
 356                 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
 357             );
 358         } else {
 359             throw new InternalError("Unimplemented size");
 360         }
 361     }
 362 
 363     // Binary operations with scalars
 364 
 365     @Override
 366     @ForceInline
 367     public $abstractvectortype$ add($type$ o) {
 368         return add(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 369     }
 370 
 371     @Override
 372     @ForceInline
 373     public $abstractvectortype$ add($type$ o, Mask<$Boxtype$> m) {
 374         return add(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 375     }
 376 
 377     @Override
 378     @ForceInline
 379     public $abstractvectortype$ sub($type$ o) {
 380         return sub(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 381     }
 382 
 383     @Override
 384     @ForceInline
 385     public $abstractvectortype$ sub($type$ o, Mask<$Boxtype$> m) {
 386         return sub(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 387     }
 388 
 389     @Override
 390     @ForceInline
 391     public $abstractvectortype$ mul($type$ o) {
 392         return mul(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 393     }
 394 
 395     @Override
 396     @ForceInline
 397     public $abstractvectortype$ mul($type$ o, Mask<$Boxtype$> m) {
 398         return mul(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 399     }
 400 
 401     @Override
 402     @ForceInline
 403     public $abstractvectortype$ min($type$ o) {
 404         return min(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 405     }
 406 
 407     @Override
 408     @ForceInline
 409     public $abstractvectortype$ max($type$ o) {
 410         return max(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 411     }
 412 
 413     @Override
 414     @ForceInline
 415     public Mask<$Boxtype$> equal($type$ o) {
 416         return equal(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 417     }
 418 
 419     @Override
 420     @ForceInline
 421     public Mask<$Boxtype$> notEqual($type$ o) {
 422         return notEqual(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 423     }
 424 
 425     @Override
 426     @ForceInline
 427     public Mask<$Boxtype$> lessThan($type$ o) {
 428         return lessThan(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 429     }
 430 
 431     @Override
 432     @ForceInline
 433     public Mask<$Boxtype$> lessThanEq($type$ o) {
 434         return lessThanEq(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 435     }
 436 
 437     @Override
 438     @ForceInline
 439     public Mask<$Boxtype$> greaterThan($type$ o) {
 440         return greaterThan(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 441     }
 442 
 443     @Override
 444     @ForceInline
 445     public Mask<$Boxtype$> greaterThanEq($type$ o) {
 446         return greaterThanEq(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 447     }
 448 
 449     @Override
 450     @ForceInline
 451     public $abstractvectortype$ blend($type$ o, Mask<$Boxtype$> m) {
 452         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 453     }
 454 
 455 #if[FP]
 456     @Override
 457     @ForceInline
 458     public $abstractvectortype$ div($type$ o) {
 459         return div(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 460     }
 461 
 462     @Override
 463     @ForceInline
 464     public $abstractvectortype$ div($type$ o, Mask<$Boxtype$> m) {
 465         return div(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 466     }
 467 
 468     @Override
 469     @ForceInline
 470     public $vectortype$ div(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
 471         return blend(div(v), m);
 472     }
 473 
 474     @Override
 475     @ForceInline
 476     public $abstractvectortype$ atan2($type$ o) {
 477         return atan2(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 478     }
 479 
 480     @Override
 481     @ForceInline
 482     public $abstractvectortype$ atan2($type$ o, Mask<$Boxtype$> m) {
 483         return atan2(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 484     }
 485 
 486     @Override
 487     @ForceInline
 488     public $abstractvectortype$ pow($type$ o) {
 489         return pow(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 490     }
 491 
 492     @Override
 493     @ForceInline
 494     public $abstractvectortype$ pow($type$ o, Mask<$Boxtype$> m) {
 495         return pow(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 496     }
 497 
 498     @Override
 499     @ForceInline
 500     public $abstractvectortype$ fma($type$ o1, $type$ o2) {
 501         return fma(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o1), ($vectortype$)$abstractvectortype$.broadcast(SPECIES, o2));
 502     }
 503 
 504     @Override
 505     @ForceInline
 506     public $abstractvectortype$ fma($type$ o1, $type$ o2, Mask<$Boxtype$> m) {
 507         return fma(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o1), ($vectortype$)$abstractvectortype$.broadcast(SPECIES, o2), m);
 508     }
 509 
 510     @Override
 511     @ForceInline
 512     public $abstractvectortype$ hypot($type$ o) {
 513         return hypot(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 514     }
 515 
 516     @Override
 517     @ForceInline
 518     public $abstractvectortype$ hypot($type$ o, Mask<$Boxtype$> m) {
 519         return hypot(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 520     }
 521 #end[FP]
 522 
 523 #if[BITWISE]
 524     @Override
 525     @ForceInline
 526     public $abstractvectortype$ and($type$ o) {
 527         return and(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 528     }
 529 
 530     @Override
 531     @ForceInline
 532     public $abstractvectortype$ and($type$ o, Mask<$Boxtype$> m) {
 533         return and(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 534     }
 535 
 536     @Override
 537     @ForceInline
 538     public $abstractvectortype$ or($type$ o) {
 539         return or(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 540     }
 541 
 542     @Override
 543     @ForceInline
 544     public $abstractvectortype$ or($type$ o, Mask<$Boxtype$> m) {
 545         return or(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 546     }
 547 
 548     @Override
 549     @ForceInline
 550     public $abstractvectortype$ xor($type$ o) {
 551         return xor(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
 552     }
 553 
 554     @Override
 555     @ForceInline
 556     public $abstractvectortype$ xor($type$ o, Mask<$Boxtype$> m) {
 557         return xor(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
 558     }
 559 
 560     @Override
 561     @ForceInline
 562     public $vectortype$ neg() {
 563         return ($vectortype$)zero(SPECIES).sub(this);
 564     }
 565 #end[BITWISE]
 566 
 567     // Unary operations
 568 
 569     @ForceInline
 570     @Override
 571     public $vectortype$ neg(Mask<$Boxtype$> m) {
 572         return blend(neg(), m);
 573     }
 574 
 575     @Override
 576     @ForceInline
 577     public $vectortype$ abs() {


1069     @Override
1070     @ForceInline
1071     public $vectortype$ aShiftR(int s) {
1072         return VectorIntrinsics.broadcastInt(
1073             VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1074             this, s,
1075             (v, i) -> v.uOp((__, a) -> ($type$) (a >> i)));
1076     }
1077 
1078     @Override
1079     @ForceInline
1080     public $vectortype$ aShiftR(int s, Mask<$Boxtype$> m) {
1081         return blend(aShiftR(s), m);
1082     }
1083 
1084     @Override
1085     @ForceInline
1086     public $vectortype$ shiftL(Vector<$Boxtype$> s) {
1087         $vectortype$ shiftv = ($vectortype$)s;
1088         // As per shift specification for Java, mask the shift count.
1089         shiftv = shiftv.and($abstractvectortype$.broadcast(SPECIES, {#if[int]?0x1f:0x3f}));
1090         return VectorIntrinsics.binaryOp(
1091             VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
1092             this, shiftv,
1093             (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a << b)));
1094     }
1095 
1096     @Override
1097     @ForceInline
1098     public $vectortype$ shiftR(Vector<$Boxtype$> s) {
1099         $vectortype$ shiftv = ($vectortype$)s;
1100         // As per shift specification for Java, mask the shift count.
1101         shiftv = shiftv.and($abstractvectortype$.broadcast(SPECIES, {#if[int]?0x1f:0x3f}));
1102         return VectorIntrinsics.binaryOp(
1103             VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
1104             this, shiftv,
1105             (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a >>> b)));
1106     }
1107 
1108     @Override
1109     @ForceInline
1110     public $vectortype$ aShiftR(Vector<$Boxtype$> s) {
1111         $vectortype$ shiftv = ($vectortype$)s;
1112         // As per shift specification for Java, mask the shift count.
1113         shiftv = shiftv.and($abstractvectortype$.broadcast(SPECIES, {#if[int]?0x1f:0x3f}));
1114         return VectorIntrinsics.binaryOp(
1115             VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1116             this, shiftv,
1117             (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a >> b)));
1118     }
1119 #end[intOrLong]
1120     // Ternary operations
1121 
1122 #if[FP]
1123     @Override
1124     @ForceInline
1125     public $vectortype$ fma(Vector<$Boxtype$> o1, Vector<$Boxtype$> o2) {
1126         Objects.requireNonNull(o1);
1127         Objects.requireNonNull(o2);
1128         $vectortype$ v1 = ($vectortype$)o1;
1129         $vectortype$ v2 = ($vectortype$)o2;
1130         return VectorIntrinsics.ternaryOp(
1131             VECTOR_OP_FMA, $vectortype$.class, $type$.class, LENGTH,
1132             this, v1, v2,
1133             (w1, w2, w3) -> w1.tOp(w2, w3, (i, a, b, c) -> Math.fma(a, b, c)));


1141     @ForceInline
1142     public $type$ addAll() {
1143         return ($type$) VectorIntrinsics.reductionCoerced(
1144             VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1145             this,
1146             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b)));
1147     }
1148 
1149     @Override
1150     @ForceInline
1151     public $type$ andAll() {
1152         return ($type$) VectorIntrinsics.reductionCoerced(
1153             VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
1154             this,
1155             v -> (long) v.rOp(($type$) -1, (i, a, b) -> ($type$) (a & b)));
1156     }
1157 
1158     @Override
1159     @ForceInline
1160     public $type$ andAll(Mask<$Boxtype$> m) {
1161         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) -1), m).andAll();
1162     }
1163 
1164     @Override
1165     @ForceInline
1166     public $type$ minAll() {
1167         return ($type$) VectorIntrinsics.reductionCoerced(
1168             VECTOR_OP_MIN, $vectortype$.class, $type$.class, LENGTH,
1169             this,
1170             v -> (long) v.rOp($Boxtype$.MAX_VALUE , (i, a, b) -> ($type$) Math.min(a, b)));
1171     }
1172 
1173     @Override
1174     @ForceInline
1175     public $type$ maxAll() {
1176         return ($type$) VectorIntrinsics.reductionCoerced(
1177             VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1178             this,
1179             v -> (long) v.rOp($Boxtype$.MIN_VALUE , (i, a, b) -> ($type$) Math.max(a, b)));
1180     }
1181 


1183     @ForceInline
1184     public $type$ mulAll() {
1185         return ($type$) VectorIntrinsics.reductionCoerced(
1186             VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
1187             this,
1188             v -> (long) v.rOp(($type$) 1, (i, a, b) -> ($type$) (a * b)));
1189     }
1190 
1191     @Override
1192     @ForceInline
1193     public $type$ orAll() {
1194         return ($type$) VectorIntrinsics.reductionCoerced(
1195             VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
1196             this,
1197             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a | b)));
1198     }
1199 
1200     @Override
1201     @ForceInline
1202     public $type$ orAll(Mask<$Boxtype$> m) {
1203         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).orAll();
1204     }
1205 
1206     @Override
1207     @ForceInline
1208     public $type$ xorAll() {
1209         return ($type$) VectorIntrinsics.reductionCoerced(
1210             VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
1211             this,
1212             v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a ^ b)));
1213     }
1214 
1215     @Override
1216     @ForceInline
1217     public $type$ xorAll(Mask<$Boxtype$> m) {
1218         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).xorAll();
1219     }
1220 #end[BITWISE]
1221 
1222 #if[FP]
1223     @Override
1224     @ForceInline
1225     public $type$ addAll() {
1226         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1227                                 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1228                                 this,
1229                                 v -> {
1230                                     $type$ r = v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b));
1231                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
1232                                 });
1233         return $Type$.$bitstype$BitsTo$Fptype$(bits);
1234     }
1235 
1236     @Override
1237     @ForceInline
1238     public $type$ mulAll() {


1260     }
1261 
1262     @Override
1263     @ForceInline
1264     public $type$ maxAll() {
1265         $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1266                                 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1267                                 this,
1268                                 v -> {
1269                                     $type$ r = v.rOp($Boxtype$.MIN_VALUE , (i, a, b) -> ($type$) Math.max(a, b));
1270                                     return (long)$Type$.$type$To$Bitstype$Bits(r);
1271                                 });
1272         return $Type$.$bitstype$BitsTo$Fptype$(bits);
1273     }
1274 
1275 #end[FP]
1276 
1277     @Override
1278     @ForceInline
1279     public $type$ addAll(Mask<$Boxtype$> m) {
1280         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).addAll();
1281     }
1282 
1283 
1284     @Override
1285     @ForceInline
1286     public $type$ mulAll(Mask<$Boxtype$> m) {
1287         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 1), m).mulAll();
1288     }
1289 
1290     @Override
1291     @ForceInline
1292     public $type$ minAll(Mask<$Boxtype$> m) {
1293         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, $Boxtype$.MAX_VALUE), m).minAll();
1294     }
1295 
1296     @Override
1297     @ForceInline
1298     public $type$ maxAll(Mask<$Boxtype$> m) {
1299         return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, $Boxtype$.MIN_VALUE), m).maxAll();
1300     }
1301 
1302     @Override
1303     @ForceInline
1304     public Shuffle<$Boxtype$> toShuffle() {
1305         $type$[] a = toArray();
1306         int[] sa = new int[a.length];
1307         for (int i = 0; i < a.length; i++) {
1308             sa[i] = (int) a[i];
1309         }
1310         return $abstractvectortype$.shuffleFromArray(SPECIES, sa, 0);
1311     }
1312 
1313     // Memory operations
1314 
1315     private static final int ARRAY_SHIFT         = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE);
1316     private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
1317 
1318     @Override
1319     @ForceInline


1328     }
1329 
1330     @Override
1331     @ForceInline
1332     public final void intoArray($type$[] a, int ax, Mask<$Boxtype$> m) {
1333         $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax);
1334         $abstractvectortype$ newVal = oldVal.blend(this, m);
1335         newVal.intoArray(a, ax);
1336     }
1337 #if[!byteOrShort]
1338     @Override
1339     @ForceInline
1340     public void intoArray($type$[] a, int ix, int[] b, int iy) {
1341 #if[longOrDouble64]
1342         this.intoArray(a, ix + b[iy]);
1343 #else[longOrDouble64]
1344         Objects.requireNonNull(a);
1345         Objects.requireNonNull(b);
1346 
1347         // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
1348         IntVector vix = IntVector.fromArray(INDEX_SPECIES, b, iy).add(ix);
1349 
1350         vix = VectorIntrinsics.checkIndex(vix, a.length);
1351 
1352         VectorIntrinsics.storeWithMap($vectortype$.class, $type$.class, LENGTH, $vectorindextype$,
1353                                a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix,
1354                                this,
1355                                a, ix, b, iy,
1356                                (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
1357 #end[longOrDouble64]
1358     }
1359 
1360      @Override
1361      @ForceInline
1362      public final void intoArray($type$[] a, int ax, Mask<$Boxtype$> m, int[] b, int iy) {
1363          // @@@ This can result in out of bounds errors for unset mask lanes
1364          $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax, b, iy);
1365          $abstractvectortype$ newVal = oldVal.blend(this, m);
1366          newVal.intoArray(a, ax, b, iy);
1367      }
1368 #end[!byteOrShort]


1747             boolean[] res = new boolean[species().length()];
1748             boolean[] bits = getBits();
1749             for (int i = 0; i < species().length(); i++) {
1750                 res[i] = f.apply(i, bits[i]);
1751             }
1752             return new $masktype$(res);
1753         }
1754 
1755         @Override
1756         $masktype$ bOp(Mask<$Boxtype$> o, MBinOp f) {
1757             boolean[] res = new boolean[species().length()];
1758             boolean[] bits = getBits();
1759             boolean[] mbits = (($masktype$)o).getBits();
1760             for (int i = 0; i < species().length(); i++) {
1761                 res[i] = f.apply(i, bits[i], mbits[i]);
1762             }
1763             return new $masktype$(res);
1764         }
1765 
1766         @Override
1767         public Species<$Boxtype$> species() {
1768             return SPECIES;
1769         }
1770 
1771         @Override
1772         public $vectortype$ toVector() {
1773             $type$[] res = new $type$[species().length()];
1774             boolean[] bits = getBits();
1775             for (int i = 0; i < species().length(); i++) {
1776                 // -1 will result in the most significant bit being set in
1777                 // addition to some or all other bits
1778                 res[i] = ($type$) (bits[i] ? -1 : 0);
1779             }
1780             return new $vectortype$(res);
1781         }
1782 
1783         @Override
1784         @ForceInline
1785         @SuppressWarnings("unchecked")
1786         public <E> Mask<E> cast(Species<E> species) {
1787             if (length() != species.length())
1788                 throw new IllegalArgumentException("Mask length and species length differ");
1789             Class<?> stype = species.elementType();
1790             boolean [] maskArray = toArray();
1791             if (stype == byte.class) {
1792                 return (Mask <E>) new Byte$bits$Vector.Byte$bits$Mask(maskArray);
1793             } else if (stype == short.class) {
1794                 return (Mask <E>) new Short$bits$Vector.Short$bits$Mask(maskArray);
1795             } else if (stype == int.class) {
1796                 return (Mask <E>) new Int$bits$Vector.Int$bits$Mask(maskArray);
1797             } else if (stype == long.class) {
1798                 return (Mask <E>) new Long$bits$Vector.Long$bits$Mask(maskArray);
1799             } else if (stype == float.class) {
1800                 return (Mask <E>) new Float$bits$Vector.Float$bits$Mask(maskArray);
1801             } else if (stype == double.class) {
1802                 return (Mask <E>) new Double$bits$Vector.Double$bits$Mask(maskArray);
1803             } else {
1804                 throw new UnsupportedOperationException("Bad lane type for casting.");
1805             }
1806         }
1807 
1808         // Unary operations
1809 
1810         @Override
1811         @ForceInline
1812         public $masktype$ not() {
1813             return ($masktype$) VectorIntrinsics.unaryOp(
1814                                              VECTOR_OP_NOT, $masktype$.class, $bitstype$.class, LENGTH,
1815                                              this,
1816                                              (m1) -> m1.uOp((i, a) -> !a));
1817         }
1818 
1819         // Binary operations
1820 
1821         @Override
1822         @ForceInline
1823         public $masktype$ and(Mask<$Boxtype$> o) {
1824             Objects.requireNonNull(o);
1825             $masktype$ m = ($masktype$)o;
1826             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1827                                              this, m,


1860     // Shuffle
1861 
1862     static final class $shuffletype$ extends AbstractShuffle<$Boxtype$> {
1863         $shuffletype$(byte[] reorder) {
1864             super(reorder);
1865         }
1866 
1867         public $shuffletype$(int[] reorder) {
1868             super(reorder);
1869         }
1870 
1871         public $shuffletype$(int[] reorder, int i) {
1872             super(reorder, i);
1873         }
1874 
1875         public $shuffletype$(IntUnaryOperator f) {
1876             super(f);
1877         }
1878 
1879         @Override
1880         public Species<$Boxtype$> species() {
1881             return SPECIES;
1882         }
1883 
1884         @Override
1885         public $abstractvectortype$ toVector() {
1886             $type$[] va = new $type$[SPECIES.length()];
1887             for (int i = 0; i < va.length; i++) {
1888               va[i] = ($type$) getElement(i);
1889             }
1890             return $abstractvectortype$.fromArray(SPECIES, va, 0);
1891         }
1892 
1893         @Override
1894         @ForceInline
1895         @SuppressWarnings("unchecked")
1896         public <F> Shuffle<F> cast(Species<F> species) {
1897             if (length() != species.length())
1898                 throw new IllegalArgumentException("Shuffle length and species length differ");
1899             Class<?> stype = species.elementType();
1900             int [] shuffleArray = toArray();
1901             if (stype == byte.class) {
1902                 return (Shuffle<F>) new Byte$bits$Vector.Byte$bits$Shuffle(shuffleArray);
1903             } else if (stype == short.class) {
1904                 return (Shuffle<F>) new Short$bits$Vector.Short$bits$Shuffle(shuffleArray);
1905             } else if (stype == int.class) {
1906                 return (Shuffle<F>) new Int$bits$Vector.Int$bits$Shuffle(shuffleArray);
1907             } else if (stype == long.class) {
1908                 return (Shuffle<F>) new Long$bits$Vector.Long$bits$Shuffle(shuffleArray);
1909             } else if (stype == float.class) {
1910                 return (Shuffle<F>) new Float$bits$Vector.Float$bits$Shuffle(shuffleArray);
1911             } else if (stype == double.class) {
1912                 return (Shuffle<F>) new Double$bits$Vector.Double$bits$Shuffle(shuffleArray);
1913             } else {
1914                 throw new UnsupportedOperationException("Bad lane type for casting.");
1915             }
1916         }
1917 
1918         @Override
1919         public $shuffletype$ rearrange(Vector.Shuffle<$Boxtype$> o) {
1920             $shuffletype$ s = ($shuffletype$) o;
1921             byte[] r = new byte[reorder.length];
1922             for (int i = 0; i < reorder.length; i++) {
1923                 r[i] = reorder[s.reorder[i]];
1924             }
1925             return new $shuffletype$(r);
1926         }
1927     }
1928 
1929     // Species
1930 
1931     @Override
1932     public Species<$Boxtype$> species() {
1933         return SPECIES;








































































































































































1934     }
1935 }
< prev index next >