1 /* 2 * Copyright (c) 2017, 2022, 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 any 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 java.util.function.IntUnaryOperator; 31 32 import jdk.internal.vm.annotation.ForceInline; 33 import jdk.internal.vm.vector.VectorSupport; 34 35 import static jdk.internal.vm.vector.VectorSupport.*; 36 37 import static jdk.incubator.vector.VectorOperators.*; 38 39 // -- This file was mechanically generated: Do not edit! -- // 40 41 @SuppressWarnings("cast") // warning: redundant cast 42 final class Byte256Vector extends ByteVector { 43 static final ByteSpecies VSPECIES = 44 (ByteSpecies) ByteVector.SPECIES_256; 45 46 static final VectorShape VSHAPE = 47 VSPECIES.vectorShape(); 48 49 static final Class<Byte256Vector> VCLASS = Byte256Vector.class; 50 51 static final int VSIZE = VSPECIES.vectorBitSize(); 52 53 static final int VLENGTH = VSPECIES.laneCount(); // used by the JVM 54 55 static final Class<Byte> ETYPE = byte.class; // used by the JVM 56 57 Byte256Vector(byte[] v) { 58 super(v); 59 } 60 61 // For compatibility as Byte256Vector::new, 62 // stored into species.vectorFactory. 63 Byte256Vector(Object v) { 64 this((byte[]) v); 65 } 66 67 static final Byte256Vector ZERO = new Byte256Vector(new byte[VLENGTH]); 68 static final Byte256Vector IOTA = new Byte256Vector(VSPECIES.iotaArray()); 69 70 static { 71 // Warm up a few species caches. 72 // If we do this too much we will 73 // get NPEs from bootstrap circularity. 74 VSPECIES.dummyVector(); 75 VSPECIES.withLanes(LaneType.BYTE); 76 } 77 78 // Specialized extractors 79 80 @ForceInline 81 final @Override 82 public ByteSpecies vspecies() { 83 // ISSUE: This should probably be a @Stable 84 // field inside AbstractVector, rather than 85 // a megamorphic method. 86 return VSPECIES; 87 } 88 89 @ForceInline 90 @Override 91 public final Class<Byte> elementType() { return byte.class; } 92 93 @ForceInline 94 @Override 95 public final int elementSize() { return Byte.SIZE; } 96 97 @ForceInline 98 @Override 99 public final VectorShape shape() { return VSHAPE; } 100 101 @ForceInline 102 @Override 103 public final int length() { return VLENGTH; } 104 105 @ForceInline 106 @Override 107 public final int bitSize() { return VSIZE; } 108 109 @ForceInline 110 @Override 111 public final int byteSize() { return VSIZE / Byte.SIZE; } 112 113 /*package-private*/ 114 @ForceInline 115 final @Override 116 byte[] vec() { 117 return (byte[])getPayload(); 118 } 119 120 // Virtualized constructors 121 122 @Override 123 @ForceInline 124 public final Byte256Vector broadcast(byte e) { 125 return (Byte256Vector) super.broadcastTemplate(e); // specialize 126 } 127 128 @Override 129 @ForceInline 130 public final Byte256Vector broadcast(long e) { 131 return (Byte256Vector) super.broadcastTemplate(e); // specialize 132 } 133 134 @Override 135 @ForceInline 136 Byte256Mask maskFromArray(boolean[] bits) { 137 return new Byte256Mask(bits); 138 } 139 140 @Override 141 @ForceInline 142 Byte256Shuffle iotaShuffle() { return Byte256Shuffle.IOTA; } 143 144 @ForceInline 145 Byte256Shuffle iotaShuffle(int start, int step, boolean wrap) { 146 if (wrap) { 147 return (Byte256Shuffle)VectorSupport.shuffleIota(ETYPE, Byte256Shuffle.class, VSPECIES, VLENGTH, start, step, 1, 148 (l, lstart, lstep, s) -> s.shuffleFromOp(i -> (VectorIntrinsics.wrapToRange(i*lstep + lstart, l)))); 149 } else { 150 return (Byte256Shuffle)VectorSupport.shuffleIota(ETYPE, Byte256Shuffle.class, VSPECIES, VLENGTH, start, step, 0, 151 (l, lstart, lstep, s) -> s.shuffleFromOp(i -> (i*lstep + lstart))); 152 } 153 } 154 155 @Override 156 @ForceInline 157 Byte256Shuffle shuffleFromBytes(byte[] reorder) { return new Byte256Shuffle(reorder); } 158 159 @Override 160 @ForceInline 161 Byte256Shuffle shuffleFromArray(int[] indexes, int i) { return new Byte256Shuffle(indexes, i); } 162 163 @Override 164 @ForceInline 165 Byte256Shuffle shuffleFromOp(IntUnaryOperator fn) { return new Byte256Shuffle(fn); } 166 167 // Make a vector of the same species but the given elements: 168 @ForceInline 169 final @Override 170 Byte256Vector vectorFactory(byte[] vec) { 171 return new Byte256Vector(vec); 172 } 173 174 @ForceInline 175 final @Override 176 Byte256Vector asByteVectorRaw() { 177 return (Byte256Vector) super.asByteVectorRawTemplate(); // specialize 178 } 179 180 @ForceInline 181 final @Override 182 AbstractVector<?> asVectorRaw(LaneType laneType) { 183 return super.asVectorRawTemplate(laneType); // specialize 184 } 185 186 // Unary operator 187 188 @ForceInline 189 final @Override 190 Byte256Vector uOp(FUnOp f) { 191 return (Byte256Vector) super.uOpTemplate(f); // specialize 192 } 193 194 @ForceInline 195 final @Override 196 Byte256Vector uOp(VectorMask<Byte> m, FUnOp f) { 197 return (Byte256Vector) 198 super.uOpTemplate((Byte256Mask)m, f); // specialize 199 } 200 201 // Binary operator 202 203 @ForceInline 204 final @Override 205 Byte256Vector bOp(Vector<Byte> v, FBinOp f) { 206 return (Byte256Vector) super.bOpTemplate((Byte256Vector)v, f); // specialize 207 } 208 209 @ForceInline 210 final @Override 211 Byte256Vector bOp(Vector<Byte> v, 212 VectorMask<Byte> m, FBinOp f) { 213 return (Byte256Vector) 214 super.bOpTemplate((Byte256Vector)v, (Byte256Mask)m, 215 f); // specialize 216 } 217 218 // Ternary operator 219 220 @ForceInline 221 final @Override 222 Byte256Vector tOp(Vector<Byte> v1, Vector<Byte> v2, FTriOp f) { 223 return (Byte256Vector) 224 super.tOpTemplate((Byte256Vector)v1, (Byte256Vector)v2, 225 f); // specialize 226 } 227 228 @ForceInline 229 final @Override 230 Byte256Vector tOp(Vector<Byte> v1, Vector<Byte> v2, 231 VectorMask<Byte> m, FTriOp f) { 232 return (Byte256Vector) 233 super.tOpTemplate((Byte256Vector)v1, (Byte256Vector)v2, 234 (Byte256Mask)m, f); // specialize 235 } 236 237 @ForceInline 238 final @Override 239 byte rOp(byte v, VectorMask<Byte> m, FBinOp f) { 240 return super.rOpTemplate(v, m, f); // specialize 241 } 242 243 @Override 244 @ForceInline 245 public final <F> 246 Vector<F> convertShape(VectorOperators.Conversion<Byte,F> conv, 247 VectorSpecies<F> rsp, int part) { 248 return super.convertShapeTemplate(conv, rsp, part); // specialize 249 } 250 251 @Override 252 @ForceInline 253 public final <F> 254 Vector<F> reinterpretShape(VectorSpecies<F> toSpecies, int part) { 255 return super.reinterpretShapeTemplate(toSpecies, part); // specialize 256 } 257 258 // Specialized algebraic operations: 259 260 // The following definition forces a specialized version of this 261 // crucial method into the v-table of this class. A call to add() 262 // will inline to a call to lanewise(ADD,), at which point the JIT 263 // intrinsic will have the opcode of ADD, plus all the metadata 264 // for this particular class, enabling it to generate precise 265 // code. 266 // 267 // There is probably no benefit to the JIT to specialize the 268 // masked or broadcast versions of the lanewise method. 269 270 @Override 271 @ForceInline 272 public Byte256Vector lanewise(Unary op) { 273 return (Byte256Vector) super.lanewiseTemplate(op); // specialize 274 } 275 276 @Override 277 @ForceInline 278 public Byte256Vector lanewise(Unary op, VectorMask<Byte> m) { 279 return (Byte256Vector) super.lanewiseTemplate(op, Byte256Mask.class, (Byte256Mask) m); // specialize 280 } 281 282 @Override 283 @ForceInline 284 public Byte256Vector lanewise(Binary op, Vector<Byte> v) { 285 return (Byte256Vector) super.lanewiseTemplate(op, v); // specialize 286 } 287 288 @Override 289 @ForceInline 290 public Byte256Vector lanewise(Binary op, Vector<Byte> v, VectorMask<Byte> m) { 291 return (Byte256Vector) super.lanewiseTemplate(op, Byte256Mask.class, v, (Byte256Mask) m); // specialize 292 } 293 294 /*package-private*/ 295 @Override 296 @ForceInline Byte256Vector 297 lanewiseShift(VectorOperators.Binary op, int e) { 298 return (Byte256Vector) super.lanewiseShiftTemplate(op, e); // specialize 299 } 300 301 /*package-private*/ 302 @Override 303 @ForceInline Byte256Vector 304 lanewiseShift(VectorOperators.Binary op, int e, VectorMask<Byte> m) { 305 return (Byte256Vector) super.lanewiseShiftTemplate(op, Byte256Mask.class, e, (Byte256Mask) m); // specialize 306 } 307 308 /*package-private*/ 309 @Override 310 @ForceInline 311 public final 312 Byte256Vector 313 lanewise(Ternary op, Vector<Byte> v1, Vector<Byte> v2) { 314 return (Byte256Vector) super.lanewiseTemplate(op, v1, v2); // specialize 315 } 316 317 @Override 318 @ForceInline 319 public final 320 Byte256Vector 321 lanewise(Ternary op, Vector<Byte> v1, Vector<Byte> v2, VectorMask<Byte> m) { 322 return (Byte256Vector) super.lanewiseTemplate(op, Byte256Mask.class, v1, v2, (Byte256Mask) m); // specialize 323 } 324 325 @Override 326 @ForceInline 327 public final 328 Byte256Vector addIndex(int scale) { 329 return (Byte256Vector) super.addIndexTemplate(scale); // specialize 330 } 331 332 // Type specific horizontal reductions 333 334 @Override 335 @ForceInline 336 public final byte reduceLanes(VectorOperators.Associative op) { 337 return super.reduceLanesTemplate(op); // specialized 338 } 339 340 @Override 341 @ForceInline 342 public final byte reduceLanes(VectorOperators.Associative op, 343 VectorMask<Byte> m) { 344 return super.reduceLanesTemplate(op, Byte256Mask.class, (Byte256Mask) m); // specialized 345 } 346 347 @Override 348 @ForceInline 349 public final long reduceLanesToLong(VectorOperators.Associative op) { 350 return (long) super.reduceLanesTemplate(op); // specialized 351 } 352 353 @Override 354 @ForceInline 355 public final long reduceLanesToLong(VectorOperators.Associative op, 356 VectorMask<Byte> m) { 357 return (long) super.reduceLanesTemplate(op, Byte256Mask.class, (Byte256Mask) m); // specialized 358 } 359 360 @ForceInline 361 public VectorShuffle<Byte> toShuffle() { 362 return super.toShuffleTemplate(Byte256Shuffle.class); // specialize 363 } 364 365 // Specialized unary testing 366 367 @Override 368 @ForceInline 369 public final Byte256Mask test(Test op) { 370 return super.testTemplate(Byte256Mask.class, op); // specialize 371 } 372 373 @Override 374 @ForceInline 375 public final Byte256Mask test(Test op, VectorMask<Byte> m) { 376 return super.testTemplate(Byte256Mask.class, op, (Byte256Mask) m); // specialize 377 } 378 379 // Specialized comparisons 380 381 @Override 382 @ForceInline 383 public final Byte256Mask compare(Comparison op, Vector<Byte> v) { 384 return super.compareTemplate(Byte256Mask.class, op, v); // specialize 385 } 386 387 @Override 388 @ForceInline 389 public final Byte256Mask compare(Comparison op, byte s) { 390 return super.compareTemplate(Byte256Mask.class, op, s); // specialize 391 } 392 393 @Override 394 @ForceInline 395 public final Byte256Mask compare(Comparison op, long s) { 396 return super.compareTemplate(Byte256Mask.class, op, s); // specialize 397 } 398 399 @Override 400 @ForceInline 401 public final Byte256Mask compare(Comparison op, Vector<Byte> v, VectorMask<Byte> m) { 402 return super.compareTemplate(Byte256Mask.class, op, v, (Byte256Mask) m); 403 } 404 405 406 @Override 407 @ForceInline 408 public Byte256Vector blend(Vector<Byte> v, VectorMask<Byte> m) { 409 return (Byte256Vector) 410 super.blendTemplate(Byte256Mask.class, 411 (Byte256Vector) v, 412 (Byte256Mask) m); // specialize 413 } 414 415 @Override 416 @ForceInline 417 public Byte256Vector slice(int origin, Vector<Byte> v) { 418 return (Byte256Vector) super.sliceTemplate(origin, v); // specialize 419 } 420 421 @Override 422 @ForceInline 423 public Byte256Vector slice(int origin) { 424 return (Byte256Vector) super.sliceTemplate(origin); // specialize 425 } 426 427 @Override 428 @ForceInline 429 public Byte256Vector unslice(int origin, Vector<Byte> w, int part) { 430 return (Byte256Vector) super.unsliceTemplate(origin, w, part); // specialize 431 } 432 433 @Override 434 @ForceInline 435 public Byte256Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<Byte> m) { 436 return (Byte256Vector) 437 super.unsliceTemplate(Byte256Mask.class, 438 origin, w, part, 439 (Byte256Mask) m); // specialize 440 } 441 442 @Override 443 @ForceInline 444 public Byte256Vector unslice(int origin) { 445 return (Byte256Vector) super.unsliceTemplate(origin); // specialize 446 } 447 448 @Override 449 @ForceInline 450 public Byte256Vector rearrange(VectorShuffle<Byte> s) { 451 return (Byte256Vector) 452 super.rearrangeTemplate(Byte256Shuffle.class, 453 (Byte256Shuffle) s); // specialize 454 } 455 456 @Override 457 @ForceInline 458 public Byte256Vector rearrange(VectorShuffle<Byte> shuffle, 459 VectorMask<Byte> m) { 460 return (Byte256Vector) 461 super.rearrangeTemplate(Byte256Shuffle.class, 462 Byte256Mask.class, 463 (Byte256Shuffle) shuffle, 464 (Byte256Mask) m); // specialize 465 } 466 467 @Override 468 @ForceInline 469 public Byte256Vector rearrange(VectorShuffle<Byte> s, 470 Vector<Byte> v) { 471 return (Byte256Vector) 472 super.rearrangeTemplate(Byte256Shuffle.class, 473 (Byte256Shuffle) s, 474 (Byte256Vector) v); // specialize 475 } 476 477 @Override 478 @ForceInline 479 public Byte256Vector selectFrom(Vector<Byte> v) { 480 return (Byte256Vector) 481 super.selectFromTemplate((Byte256Vector) v); // specialize 482 } 483 484 @Override 485 @ForceInline 486 public Byte256Vector selectFrom(Vector<Byte> v, 487 VectorMask<Byte> m) { 488 return (Byte256Vector) 489 super.selectFromTemplate((Byte256Vector) v, 490 (Byte256Mask) m); // specialize 491 } 492 493 494 @ForceInline 495 @Override 496 public byte lane(int i) { 497 switch(i) { 498 case 0: return laneHelper(0); 499 case 1: return laneHelper(1); 500 case 2: return laneHelper(2); 501 case 3: return laneHelper(3); 502 case 4: return laneHelper(4); 503 case 5: return laneHelper(5); 504 case 6: return laneHelper(6); 505 case 7: return laneHelper(7); 506 case 8: return laneHelper(8); 507 case 9: return laneHelper(9); 508 case 10: return laneHelper(10); 509 case 11: return laneHelper(11); 510 case 12: return laneHelper(12); 511 case 13: return laneHelper(13); 512 case 14: return laneHelper(14); 513 case 15: return laneHelper(15); 514 case 16: return laneHelper(16); 515 case 17: return laneHelper(17); 516 case 18: return laneHelper(18); 517 case 19: return laneHelper(19); 518 case 20: return laneHelper(20); 519 case 21: return laneHelper(21); 520 case 22: return laneHelper(22); 521 case 23: return laneHelper(23); 522 case 24: return laneHelper(24); 523 case 25: return laneHelper(25); 524 case 26: return laneHelper(26); 525 case 27: return laneHelper(27); 526 case 28: return laneHelper(28); 527 case 29: return laneHelper(29); 528 case 30: return laneHelper(30); 529 case 31: return laneHelper(31); 530 default: throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH); 531 } 532 } 533 534 public byte laneHelper(int i) { 535 return (byte) VectorSupport.extract( 536 VCLASS, ETYPE, VLENGTH, 537 this, i, 538 (vec, ix) -> { 539 byte[] vecarr = vec.vec(); 540 return (long)vecarr[ix]; 541 }); 542 } 543 544 @ForceInline 545 @Override 546 public Byte256Vector withLane(int i, byte e) { 547 switch (i) { 548 case 0: return withLaneHelper(0, e); 549 case 1: return withLaneHelper(1, e); 550 case 2: return withLaneHelper(2, e); 551 case 3: return withLaneHelper(3, e); 552 case 4: return withLaneHelper(4, e); 553 case 5: return withLaneHelper(5, e); 554 case 6: return withLaneHelper(6, e); 555 case 7: return withLaneHelper(7, e); 556 case 8: return withLaneHelper(8, e); 557 case 9: return withLaneHelper(9, e); 558 case 10: return withLaneHelper(10, e); 559 case 11: return withLaneHelper(11, e); 560 case 12: return withLaneHelper(12, e); 561 case 13: return withLaneHelper(13, e); 562 case 14: return withLaneHelper(14, e); 563 case 15: return withLaneHelper(15, e); 564 case 16: return withLaneHelper(16, e); 565 case 17: return withLaneHelper(17, e); 566 case 18: return withLaneHelper(18, e); 567 case 19: return withLaneHelper(19, e); 568 case 20: return withLaneHelper(20, e); 569 case 21: return withLaneHelper(21, e); 570 case 22: return withLaneHelper(22, e); 571 case 23: return withLaneHelper(23, e); 572 case 24: return withLaneHelper(24, e); 573 case 25: return withLaneHelper(25, e); 574 case 26: return withLaneHelper(26, e); 575 case 27: return withLaneHelper(27, e); 576 case 28: return withLaneHelper(28, e); 577 case 29: return withLaneHelper(29, e); 578 case 30: return withLaneHelper(30, e); 579 case 31: return withLaneHelper(31, e); 580 default: throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH); 581 } 582 } 583 584 public Byte256Vector withLaneHelper(int i, byte e) { 585 return VectorSupport.insert( 586 VCLASS, ETYPE, VLENGTH, 587 this, i, (long)e, 588 (v, ix, bits) -> { 589 byte[] res = v.vec().clone(); 590 res[ix] = (byte)bits; 591 return v.vectorFactory(res); 592 }); 593 } 594 595 // Mask 596 597 static final class Byte256Mask extends AbstractMask<Byte> { 598 static final int VLENGTH = VSPECIES.laneCount(); // used by the JVM 599 static final Class<Byte> ETYPE = byte.class; // used by the JVM 600 601 Byte256Mask(boolean[] bits) { 602 this(bits, 0); 603 } 604 605 Byte256Mask(boolean[] bits, int offset) { 606 super(prepare(bits, offset)); 607 } 608 609 Byte256Mask(boolean val) { 610 super(prepare(val)); 611 } 612 613 private static boolean[] prepare(boolean[] bits, int offset) { 614 boolean[] newBits = new boolean[VSPECIES.laneCount()]; 615 for (int i = 0; i < newBits.length; i++) { 616 newBits[i] = bits[offset + i]; 617 } 618 return newBits; 619 } 620 621 private static boolean[] prepare(boolean val) { 622 boolean[] bits = new boolean[VSPECIES.laneCount()]; 623 Arrays.fill(bits, val); 624 return bits; 625 } 626 627 @ForceInline 628 final @Override 629 public ByteSpecies vspecies() { 630 // ISSUE: This should probably be a @Stable 631 // field inside AbstractMask, rather than 632 // a megamorphic method. 633 return VSPECIES; 634 } 635 636 @ForceInline 637 boolean[] getBits() { 638 return (boolean[])getPayload(); 639 } 640 641 @Override 642 Byte256Mask uOp(MUnOp f) { 643 boolean[] res = new boolean[vspecies().laneCount()]; 644 boolean[] bits = getBits(); 645 for (int i = 0; i < res.length; i++) { 646 res[i] = f.apply(i, bits[i]); 647 } 648 return new Byte256Mask(res); 649 } 650 651 @Override 652 Byte256Mask bOp(VectorMask<Byte> m, MBinOp f) { 653 boolean[] res = new boolean[vspecies().laneCount()]; 654 boolean[] bits = getBits(); 655 boolean[] mbits = ((Byte256Mask)m).getBits(); 656 for (int i = 0; i < res.length; i++) { 657 res[i] = f.apply(i, bits[i], mbits[i]); 658 } 659 return new Byte256Mask(res); 660 } 661 662 @ForceInline 663 @Override 664 public final 665 Byte256Vector toVector() { 666 return (Byte256Vector) super.toVectorTemplate(); // specialize 667 } 668 669 /** 670 * Helper function for lane-wise mask conversions. 671 * This function kicks in after intrinsic failure. 672 */ 673 @ForceInline 674 private final <E> 675 VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) { 676 if (length() != dsp.laneCount()) 677 throw new IllegalArgumentException("VectorMask length and species length differ"); 678 boolean[] maskArray = toArray(); 679 return dsp.maskFactory(maskArray).check(dsp); 680 } 681 682 @Override 683 @ForceInline 684 public <E> VectorMask<E> cast(VectorSpecies<E> dsp) { 685 AbstractSpecies<E> species = (AbstractSpecies<E>) dsp; 686 if (length() != species.laneCount()) 687 throw new IllegalArgumentException("VectorMask length and species length differ"); 688 689 return VectorSupport.convert(VectorSupport.VECTOR_OP_CAST, 690 this.getClass(), ETYPE, VLENGTH, 691 species.maskType(), species.elementType(), VLENGTH, 692 this, species, 693 (m, s) -> s.maskFactory(m.toArray()).check(s)); 694 } 695 696 @Override 697 @ForceInline 698 public Byte256Mask eq(VectorMask<Byte> mask) { 699 Objects.requireNonNull(mask); 700 Byte256Mask m = (Byte256Mask)mask; 701 return xor(m.not()); 702 } 703 704 // Unary operations 705 706 @Override 707 @ForceInline 708 public Byte256Mask not() { 709 return xor(maskAll(true)); 710 } 711 712 // Binary operations 713 714 @Override 715 @ForceInline 716 public Byte256Mask and(VectorMask<Byte> mask) { 717 Objects.requireNonNull(mask); 718 Byte256Mask m = (Byte256Mask)mask; 719 return VectorSupport.binaryOp(VECTOR_OP_AND, Byte256Mask.class, null, byte.class, VLENGTH, 720 this, m, null, 721 (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a & b)); 722 } 723 724 @Override 725 @ForceInline 726 public Byte256Mask or(VectorMask<Byte> mask) { 727 Objects.requireNonNull(mask); 728 Byte256Mask m = (Byte256Mask)mask; 729 return VectorSupport.binaryOp(VECTOR_OP_OR, Byte256Mask.class, null, byte.class, VLENGTH, 730 this, m, null, 731 (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a | b)); 732 } 733 734 @ForceInline 735 /* package-private */ 736 Byte256Mask xor(VectorMask<Byte> mask) { 737 Objects.requireNonNull(mask); 738 Byte256Mask m = (Byte256Mask)mask; 739 return VectorSupport.binaryOp(VECTOR_OP_XOR, Byte256Mask.class, null, byte.class, VLENGTH, 740 this, m, null, 741 (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a ^ b)); 742 } 743 744 // Mask Query operations 745 746 @Override 747 @ForceInline 748 public int trueCount() { 749 return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TRUECOUNT, Byte256Mask.class, byte.class, VLENGTH, this, 750 (m) -> trueCountHelper(m.getBits())); 751 } 752 753 @Override 754 @ForceInline 755 public int firstTrue() { 756 return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_FIRSTTRUE, Byte256Mask.class, byte.class, VLENGTH, this, 757 (m) -> firstTrueHelper(m.getBits())); 758 } 759 760 @Override 761 @ForceInline 762 public int lastTrue() { 763 return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_LASTTRUE, Byte256Mask.class, byte.class, VLENGTH, this, 764 (m) -> lastTrueHelper(m.getBits())); 765 } 766 767 @Override 768 @ForceInline 769 public long toLong() { 770 if (length() > Long.SIZE) { 771 throw new UnsupportedOperationException("too many lanes for one long"); 772 } 773 return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TOLONG, Byte256Mask.class, byte.class, VLENGTH, this, 774 (m) -> toLongHelper(m.getBits())); 775 } 776 777 // Reductions 778 779 @Override 780 @ForceInline 781 public boolean anyTrue() { 782 return VectorSupport.test(BT_ne, Byte256Mask.class, byte.class, VLENGTH, 783 this, vspecies().maskAll(true), 784 (m, __) -> anyTrueHelper(((Byte256Mask)m).getBits())); 785 } 786 787 @Override 788 @ForceInline 789 public boolean allTrue() { 790 return VectorSupport.test(BT_overflow, Byte256Mask.class, byte.class, VLENGTH, 791 this, vspecies().maskAll(true), 792 (m, __) -> allTrueHelper(((Byte256Mask)m).getBits())); 793 } 794 795 @ForceInline 796 /*package-private*/ 797 static Byte256Mask maskAll(boolean bit) { 798 return VectorSupport.fromBitsCoerced(Byte256Mask.class, byte.class, VLENGTH, 799 (bit ? -1 : 0), MODE_BROADCAST, null, 800 (v, __) -> (v != 0 ? TRUE_MASK : FALSE_MASK)); 801 } 802 private static final Byte256Mask TRUE_MASK = new Byte256Mask(true); 803 private static final Byte256Mask FALSE_MASK = new Byte256Mask(false); 804 805 } 806 807 // Shuffle 808 809 static final class Byte256Shuffle extends AbstractShuffle<Byte> { 810 static final int VLENGTH = VSPECIES.laneCount(); // used by the JVM 811 static final Class<Byte> ETYPE = byte.class; // used by the JVM 812 813 Byte256Shuffle(byte[] reorder) { 814 super(VLENGTH, reorder); 815 } 816 817 public Byte256Shuffle(int[] reorder) { 818 super(VLENGTH, reorder); 819 } 820 821 public Byte256Shuffle(int[] reorder, int i) { 822 super(VLENGTH, reorder, i); 823 } 824 825 public Byte256Shuffle(IntUnaryOperator fn) { 826 super(VLENGTH, fn); 827 } 828 829 @Override 830 public ByteSpecies vspecies() { 831 return VSPECIES; 832 } 833 834 static { 835 // There must be enough bits in the shuffle lanes to encode 836 // VLENGTH valid indexes and VLENGTH exceptional ones. 837 assert(VLENGTH < Byte.MAX_VALUE); 838 assert(Byte.MIN_VALUE <= -VLENGTH); 839 } 840 static final Byte256Shuffle IOTA = new Byte256Shuffle(IDENTITY); 841 842 @Override 843 @ForceInline 844 public Byte256Vector toVector() { 845 return VectorSupport.shuffleToVector(VCLASS, ETYPE, Byte256Shuffle.class, this, VLENGTH, 846 (s) -> ((Byte256Vector)(((AbstractShuffle<Byte>)(s)).toVectorTemplate()))); 847 } 848 849 @Override 850 @ForceInline 851 public <F> VectorShuffle<F> cast(VectorSpecies<F> s) { 852 AbstractSpecies<F> species = (AbstractSpecies<F>) s; 853 if (length() != species.laneCount()) 854 throw new IllegalArgumentException("VectorShuffle length and species length differ"); 855 int[] shuffleArray = toArray(); 856 return s.shuffleFromArray(shuffleArray, 0).check(s); 857 } 858 859 @ForceInline 860 @Override 861 public Byte256Shuffle rearrange(VectorShuffle<Byte> shuffle) { 862 Byte256Shuffle s = (Byte256Shuffle) shuffle; 863 byte[] reorder1 = reorder(); 864 byte[] reorder2 = s.reorder(); 865 byte[] r = new byte[reorder1.length]; 866 for (int i = 0; i < reorder1.length; i++) { 867 int ssi = reorder2[i]; 868 r[i] = reorder1[ssi]; // throws on exceptional index 869 } 870 return new Byte256Shuffle(r); 871 } 872 } 873 874 // ================================================ 875 876 // Specialized low-level memory operations. 877 878 @ForceInline 879 @Override 880 final 881 ByteVector fromArray0(byte[] a, int offset) { 882 return super.fromArray0Template(a, offset); // specialize 883 } 884 885 @ForceInline 886 @Override 887 final 888 ByteVector fromArray0(byte[] a, int offset, VectorMask<Byte> m) { 889 return super.fromArray0Template(Byte256Mask.class, a, offset, (Byte256Mask) m); // specialize 890 } 891 892 893 894 @ForceInline 895 @Override 896 final 897 ByteVector fromBooleanArray0(boolean[] a, int offset) { 898 return super.fromBooleanArray0Template(a, offset); // specialize 899 } 900 901 @ForceInline 902 @Override 903 final 904 ByteVector fromBooleanArray0(boolean[] a, int offset, VectorMask<Byte> m) { 905 return super.fromBooleanArray0Template(Byte256Mask.class, a, offset, (Byte256Mask) m); // specialize 906 } 907 908 @ForceInline 909 @Override 910 final 911 ByteVector fromByteArray0(byte[] a, int offset) { 912 return super.fromByteArray0Template(a, offset); // specialize 913 } 914 915 @ForceInline 916 @Override 917 final 918 ByteVector fromByteArray0(byte[] a, int offset, VectorMask<Byte> m) { 919 return super.fromByteArray0Template(Byte256Mask.class, a, offset, (Byte256Mask) m); // specialize 920 } 921 922 @ForceInline 923 @Override 924 final 925 ByteVector fromByteBuffer0(ByteBuffer bb, int offset) { 926 return super.fromByteBuffer0Template(bb, offset); // specialize 927 } 928 929 @ForceInline 930 @Override 931 final 932 ByteVector fromByteBuffer0(ByteBuffer bb, int offset, VectorMask<Byte> m) { 933 return super.fromByteBuffer0Template(Byte256Mask.class, bb, offset, (Byte256Mask) m); // specialize 934 } 935 936 @ForceInline 937 @Override 938 final 939 void intoArray0(byte[] a, int offset) { 940 super.intoArray0Template(a, offset); // specialize 941 } 942 943 @ForceInline 944 @Override 945 final 946 void intoArray0(byte[] a, int offset, VectorMask<Byte> m) { 947 super.intoArray0Template(Byte256Mask.class, a, offset, (Byte256Mask) m); 948 } 949 950 951 @ForceInline 952 @Override 953 final 954 void intoBooleanArray0(boolean[] a, int offset, VectorMask<Byte> m) { 955 super.intoBooleanArray0Template(Byte256Mask.class, a, offset, (Byte256Mask) m); 956 } 957 958 @ForceInline 959 @Override 960 final 961 void intoByteArray0(byte[] a, int offset) { 962 super.intoByteArray0Template(a, offset); // specialize 963 } 964 965 @ForceInline 966 @Override 967 final 968 void intoByteArray0(byte[] a, int offset, VectorMask<Byte> m) { 969 super.intoByteArray0Template(Byte256Mask.class, a, offset, (Byte256Mask) m); // specialize 970 } 971 972 @ForceInline 973 @Override 974 final 975 void intoByteBuffer0(ByteBuffer bb, int offset, VectorMask<Byte> m) { 976 super.intoByteBuffer0Template(Byte256Mask.class, bb, offset, (Byte256Mask) m); 977 } 978 979 980 // End of specialized low-level memory operations. 981 982 // ================================================ 983 984 }