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 IntMaxVector extends IntVector { 43 static final IntSpecies VSPECIES = 44 (IntSpecies) IntVector.SPECIES_MAX; 45 46 static final VectorShape VSHAPE = 47 VSPECIES.vectorShape(); 48 49 static final Class<IntMaxVector> VCLASS = IntMaxVector.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<Integer> ETYPE = int.class; // used by the JVM 56 57 IntMaxVector(int[] v) { 58 super(v); 59 } 60 61 // For compatibility as IntMaxVector::new, 62 // stored into species.vectorFactory. 63 IntMaxVector(Object v) { 64 this((int[]) v); 65 } 66 67 static final IntMaxVector ZERO = new IntMaxVector(new int[VLENGTH]); 68 static final IntMaxVector IOTA = new IntMaxVector(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 IntSpecies 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<Integer> elementType() { return int.class; } 92 93 @ForceInline 94 @Override 95 public final int elementSize() { return Integer.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 int[] vec() { 117 return (int[])getPayload(); 118 } 119 120 // Virtualized constructors 121 122 @Override 123 @ForceInline 124 public final IntMaxVector broadcast(int e) { 125 return (IntMaxVector) super.broadcastTemplate(e); // specialize 126 } 127 128 @Override 129 @ForceInline 130 public final IntMaxVector broadcast(long e) { 131 return (IntMaxVector) super.broadcastTemplate(e); // specialize 132 } 133 134 @Override 135 @ForceInline 136 IntMaxMask maskFromArray(boolean[] bits) { 137 return new IntMaxMask(bits); 138 } 139 140 @Override 141 @ForceInline 142 IntMaxShuffle iotaShuffle() { return IntMaxShuffle.IOTA; } 143 144 @ForceInline 145 IntMaxShuffle iotaShuffle(int start, int step, boolean wrap) { 146 if (wrap) { 147 return (IntMaxShuffle)VectorSupport.shuffleIota(ETYPE, IntMaxShuffle.class, VSPECIES, VLENGTH, start, step, 1, 148 (l, lstart, lstep, s) -> s.shuffleFromOp(i -> (VectorIntrinsics.wrapToRange(i*lstep + lstart, l)))); 149 } else { 150 return (IntMaxShuffle)VectorSupport.shuffleIota(ETYPE, IntMaxShuffle.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 IntMaxShuffle shuffleFromBytes(byte[] reorder) { return new IntMaxShuffle(reorder); } 158 159 @Override 160 @ForceInline 161 IntMaxShuffle shuffleFromArray(int[] indexes, int i) { return new IntMaxShuffle(indexes, i); } 162 163 @Override 164 @ForceInline 165 IntMaxShuffle shuffleFromOp(IntUnaryOperator fn) { return new IntMaxShuffle(fn); } 166 167 // Make a vector of the same species but the given elements: 168 @ForceInline 169 final @Override 170 IntMaxVector vectorFactory(int[] vec) { 171 return new IntMaxVector(vec); 172 } 173 174 @ForceInline 175 final @Override 176 ByteMaxVector asByteVectorRaw() { 177 return (ByteMaxVector) 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 IntMaxVector uOp(FUnOp f) { 191 return (IntMaxVector) super.uOpTemplate(f); // specialize 192 } 193 194 @ForceInline 195 final @Override 196 IntMaxVector uOp(VectorMask<Integer> m, FUnOp f) { 197 return (IntMaxVector) 198 super.uOpTemplate((IntMaxMask)m, f); // specialize 199 } 200 201 // Binary operator 202 203 @ForceInline 204 final @Override 205 IntMaxVector bOp(Vector<Integer> v, FBinOp f) { 206 return (IntMaxVector) super.bOpTemplate((IntMaxVector)v, f); // specialize 207 } 208 209 @ForceInline 210 final @Override 211 IntMaxVector bOp(Vector<Integer> v, 212 VectorMask<Integer> m, FBinOp f) { 213 return (IntMaxVector) 214 super.bOpTemplate((IntMaxVector)v, (IntMaxMask)m, 215 f); // specialize 216 } 217 218 // Ternary operator 219 220 @ForceInline 221 final @Override 222 IntMaxVector tOp(Vector<Integer> v1, Vector<Integer> v2, FTriOp f) { 223 return (IntMaxVector) 224 super.tOpTemplate((IntMaxVector)v1, (IntMaxVector)v2, 225 f); // specialize 226 } 227 228 @ForceInline 229 final @Override 230 IntMaxVector tOp(Vector<Integer> v1, Vector<Integer> v2, 231 VectorMask<Integer> m, FTriOp f) { 232 return (IntMaxVector) 233 super.tOpTemplate((IntMaxVector)v1, (IntMaxVector)v2, 234 (IntMaxMask)m, f); // specialize 235 } 236 237 @ForceInline 238 final @Override 239 int rOp(int v, VectorMask<Integer> 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<Integer,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 IntMaxVector lanewise(Unary op) { 273 return (IntMaxVector) super.lanewiseTemplate(op); // specialize 274 } 275 276 @Override 277 @ForceInline 278 public IntMaxVector lanewise(Unary op, VectorMask<Integer> m) { 279 return (IntMaxVector) super.lanewiseTemplate(op, IntMaxMask.class, (IntMaxMask) m); // specialize 280 } 281 282 @Override 283 @ForceInline 284 public IntMaxVector lanewise(Binary op, Vector<Integer> v) { 285 return (IntMaxVector) super.lanewiseTemplate(op, v); // specialize 286 } 287 288 @Override 289 @ForceInline 290 public IntMaxVector lanewise(Binary op, Vector<Integer> v, VectorMask<Integer> m) { 291 return (IntMaxVector) super.lanewiseTemplate(op, IntMaxMask.class, v, (IntMaxMask) m); // specialize 292 } 293 294 /*package-private*/ 295 @Override 296 @ForceInline IntMaxVector 297 lanewiseShift(VectorOperators.Binary op, int e) { 298 return (IntMaxVector) super.lanewiseShiftTemplate(op, e); // specialize 299 } 300 301 /*package-private*/ 302 @Override 303 @ForceInline IntMaxVector 304 lanewiseShift(VectorOperators.Binary op, int e, VectorMask<Integer> m) { 305 return (IntMaxVector) super.lanewiseShiftTemplate(op, IntMaxMask.class, e, (IntMaxMask) m); // specialize 306 } 307 308 /*package-private*/ 309 @Override 310 @ForceInline 311 public final 312 IntMaxVector 313 lanewise(Ternary op, Vector<Integer> v1, Vector<Integer> v2) { 314 return (IntMaxVector) super.lanewiseTemplate(op, v1, v2); // specialize 315 } 316 317 @Override 318 @ForceInline 319 public final 320 IntMaxVector 321 lanewise(Ternary op, Vector<Integer> v1, Vector<Integer> v2, VectorMask<Integer> m) { 322 return (IntMaxVector) super.lanewiseTemplate(op, IntMaxMask.class, v1, v2, (IntMaxMask) m); // specialize 323 } 324 325 @Override 326 @ForceInline 327 public final 328 IntMaxVector addIndex(int scale) { 329 return (IntMaxVector) super.addIndexTemplate(scale); // specialize 330 } 331 332 // Type specific horizontal reductions 333 334 @Override 335 @ForceInline 336 public final int reduceLanes(VectorOperators.Associative op) { 337 return super.reduceLanesTemplate(op); // specialized 338 } 339 340 @Override 341 @ForceInline 342 public final int reduceLanes(VectorOperators.Associative op, 343 VectorMask<Integer> m) { 344 return super.reduceLanesTemplate(op, IntMaxMask.class, (IntMaxMask) 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<Integer> m) { 357 return (long) super.reduceLanesTemplate(op, IntMaxMask.class, (IntMaxMask) m); // specialized 358 } 359 360 @ForceInline 361 public VectorShuffle<Integer> toShuffle() { 362 return super.toShuffleTemplate(IntMaxShuffle.class); // specialize 363 } 364 365 // Specialized unary testing 366 367 @Override 368 @ForceInline 369 public final IntMaxMask test(Test op) { 370 return super.testTemplate(IntMaxMask.class, op); // specialize 371 } 372 373 @Override 374 @ForceInline 375 public final IntMaxMask test(Test op, VectorMask<Integer> m) { 376 return super.testTemplate(IntMaxMask.class, op, (IntMaxMask) m); // specialize 377 } 378 379 // Specialized comparisons 380 381 @Override 382 @ForceInline 383 public final IntMaxMask compare(Comparison op, Vector<Integer> v) { 384 return super.compareTemplate(IntMaxMask.class, op, v); // specialize 385 } 386 387 @Override 388 @ForceInline 389 public final IntMaxMask compare(Comparison op, int s) { 390 return super.compareTemplate(IntMaxMask.class, op, s); // specialize 391 } 392 393 @Override 394 @ForceInline 395 public final IntMaxMask compare(Comparison op, long s) { 396 return super.compareTemplate(IntMaxMask.class, op, s); // specialize 397 } 398 399 @Override 400 @ForceInline 401 public final IntMaxMask compare(Comparison op, Vector<Integer> v, VectorMask<Integer> m) { 402 return super.compareTemplate(IntMaxMask.class, op, v, (IntMaxMask) m); 403 } 404 405 406 @Override 407 @ForceInline 408 public IntMaxVector blend(Vector<Integer> v, VectorMask<Integer> m) { 409 return (IntMaxVector) 410 super.blendTemplate(IntMaxMask.class, 411 (IntMaxVector) v, 412 (IntMaxMask) m); // specialize 413 } 414 415 @Override 416 @ForceInline 417 public IntMaxVector slice(int origin, Vector<Integer> v) { 418 return (IntMaxVector) super.sliceTemplate(origin, v); // specialize 419 } 420 421 @Override 422 @ForceInline 423 public IntMaxVector slice(int origin) { 424 return (IntMaxVector) super.sliceTemplate(origin); // specialize 425 } 426 427 @Override 428 @ForceInline 429 public IntMaxVector unslice(int origin, Vector<Integer> w, int part) { 430 return (IntMaxVector) super.unsliceTemplate(origin, w, part); // specialize 431 } 432 433 @Override 434 @ForceInline 435 public IntMaxVector unslice(int origin, Vector<Integer> w, int part, VectorMask<Integer> m) { 436 return (IntMaxVector) 437 super.unsliceTemplate(IntMaxMask.class, 438 origin, w, part, 439 (IntMaxMask) m); // specialize 440 } 441 442 @Override 443 @ForceInline 444 public IntMaxVector unslice(int origin) { 445 return (IntMaxVector) super.unsliceTemplate(origin); // specialize 446 } 447 448 @Override 449 @ForceInline 450 public IntMaxVector rearrange(VectorShuffle<Integer> s) { 451 return (IntMaxVector) 452 super.rearrangeTemplate(IntMaxShuffle.class, 453 (IntMaxShuffle) s); // specialize 454 } 455 456 @Override 457 @ForceInline 458 public IntMaxVector rearrange(VectorShuffle<Integer> shuffle, 459 VectorMask<Integer> m) { 460 return (IntMaxVector) 461 super.rearrangeTemplate(IntMaxShuffle.class, 462 IntMaxMask.class, 463 (IntMaxShuffle) shuffle, 464 (IntMaxMask) m); // specialize 465 } 466 467 @Override 468 @ForceInline 469 public IntMaxVector rearrange(VectorShuffle<Integer> s, 470 Vector<Integer> v) { 471 return (IntMaxVector) 472 super.rearrangeTemplate(IntMaxShuffle.class, 473 (IntMaxShuffle) s, 474 (IntMaxVector) v); // specialize 475 } 476 477 @Override 478 @ForceInline 479 public IntMaxVector selectFrom(Vector<Integer> v) { 480 return (IntMaxVector) 481 super.selectFromTemplate((IntMaxVector) v); // specialize 482 } 483 484 @Override 485 @ForceInline 486 public IntMaxVector selectFrom(Vector<Integer> v, 487 VectorMask<Integer> m) { 488 return (IntMaxVector) 489 super.selectFromTemplate((IntMaxVector) v, 490 (IntMaxMask) m); // specialize 491 } 492 493 494 @ForceInline 495 @Override 496 public int lane(int i) { 497 if (i < 0 || i >= VLENGTH) { 498 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH); 499 } 500 return laneHelper(i); 501 } 502 503 public int laneHelper(int i) { 504 return (int) VectorSupport.extract( 505 VCLASS, ETYPE, VLENGTH, 506 this, i, 507 (vec, ix) -> { 508 int[] vecarr = vec.vec(); 509 return (long)vecarr[ix]; 510 }); 511 } 512 513 @ForceInline 514 @Override 515 public IntMaxVector withLane(int i, int e) { 516 if (i < 0 || i >= VLENGTH) { 517 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH); 518 } 519 return withLaneHelper(i, e); 520 } 521 522 public IntMaxVector withLaneHelper(int i, int e) { 523 return VectorSupport.insert( 524 VCLASS, ETYPE, VLENGTH, 525 this, i, (long)e, 526 (v, ix, bits) -> { 527 int[] res = v.vec().clone(); 528 res[ix] = (int)bits; 529 return v.vectorFactory(res); 530 }); 531 } 532 533 // Mask 534 535 static final class IntMaxMask extends AbstractMask<Integer> { 536 static final int VLENGTH = VSPECIES.laneCount(); // used by the JVM 537 static final Class<Integer> ETYPE = int.class; // used by the JVM 538 539 IntMaxMask(boolean[] bits) { 540 this(bits, 0); 541 } 542 543 IntMaxMask(boolean[] bits, int offset) { 544 super(prepare(bits, offset)); 545 } 546 547 IntMaxMask(boolean val) { 548 super(prepare(val)); 549 } 550 551 private static boolean[] prepare(boolean[] bits, int offset) { 552 boolean[] newBits = new boolean[VSPECIES.laneCount()]; 553 for (int i = 0; i < newBits.length; i++) { 554 newBits[i] = bits[offset + i]; 555 } 556 return newBits; 557 } 558 559 private static boolean[] prepare(boolean val) { 560 boolean[] bits = new boolean[VSPECIES.laneCount()]; 561 Arrays.fill(bits, val); 562 return bits; 563 } 564 565 @ForceInline 566 final @Override 567 public IntSpecies vspecies() { 568 // ISSUE: This should probably be a @Stable 569 // field inside AbstractMask, rather than 570 // a megamorphic method. 571 return VSPECIES; 572 } 573 574 @ForceInline 575 boolean[] getBits() { 576 return (boolean[])getPayload(); 577 } 578 579 @Override 580 IntMaxMask uOp(MUnOp f) { 581 boolean[] res = new boolean[vspecies().laneCount()]; 582 boolean[] bits = getBits(); 583 for (int i = 0; i < res.length; i++) { 584 res[i] = f.apply(i, bits[i]); 585 } 586 return new IntMaxMask(res); 587 } 588 589 @Override 590 IntMaxMask bOp(VectorMask<Integer> m, MBinOp f) { 591 boolean[] res = new boolean[vspecies().laneCount()]; 592 boolean[] bits = getBits(); 593 boolean[] mbits = ((IntMaxMask)m).getBits(); 594 for (int i = 0; i < res.length; i++) { 595 res[i] = f.apply(i, bits[i], mbits[i]); 596 } 597 return new IntMaxMask(res); 598 } 599 600 @ForceInline 601 @Override 602 public final 603 IntMaxVector toVector() { 604 return (IntMaxVector) super.toVectorTemplate(); // specialize 605 } 606 607 /** 608 * Helper function for lane-wise mask conversions. 609 * This function kicks in after intrinsic failure. 610 */ 611 @ForceInline 612 private final <E> 613 VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) { 614 if (length() != dsp.laneCount()) 615 throw new IllegalArgumentException("VectorMask length and species length differ"); 616 boolean[] maskArray = toArray(); 617 return dsp.maskFactory(maskArray).check(dsp); 618 } 619 620 @Override 621 @ForceInline 622 public <E> VectorMask<E> cast(VectorSpecies<E> dsp) { 623 AbstractSpecies<E> species = (AbstractSpecies<E>) dsp; 624 if (length() != species.laneCount()) 625 throw new IllegalArgumentException("VectorMask length and species length differ"); 626 627 return VectorSupport.convert(VectorSupport.VECTOR_OP_CAST, 628 this.getClass(), ETYPE, VLENGTH, 629 species.maskType(), species.elementType(), VLENGTH, 630 this, species, 631 (m, s) -> s.maskFactory(m.toArray()).check(s)); 632 } 633 634 @Override 635 @ForceInline 636 public IntMaxMask eq(VectorMask<Integer> mask) { 637 Objects.requireNonNull(mask); 638 IntMaxMask m = (IntMaxMask)mask; 639 return xor(m.not()); 640 } 641 642 // Unary operations 643 644 @Override 645 @ForceInline 646 public IntMaxMask not() { 647 return xor(maskAll(true)); 648 } 649 650 // Binary operations 651 652 @Override 653 @ForceInline 654 public IntMaxMask and(VectorMask<Integer> mask) { 655 Objects.requireNonNull(mask); 656 IntMaxMask m = (IntMaxMask)mask; 657 return VectorSupport.binaryOp(VECTOR_OP_AND, IntMaxMask.class, null, int.class, VLENGTH, 658 this, m, null, 659 (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a & b)); 660 } 661 662 @Override 663 @ForceInline 664 public IntMaxMask or(VectorMask<Integer> mask) { 665 Objects.requireNonNull(mask); 666 IntMaxMask m = (IntMaxMask)mask; 667 return VectorSupport.binaryOp(VECTOR_OP_OR, IntMaxMask.class, null, int.class, VLENGTH, 668 this, m, null, 669 (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a | b)); 670 } 671 672 @ForceInline 673 /* package-private */ 674 IntMaxMask xor(VectorMask<Integer> mask) { 675 Objects.requireNonNull(mask); 676 IntMaxMask m = (IntMaxMask)mask; 677 return VectorSupport.binaryOp(VECTOR_OP_XOR, IntMaxMask.class, null, int.class, VLENGTH, 678 this, m, null, 679 (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a ^ b)); 680 } 681 682 // Mask Query operations 683 684 @Override 685 @ForceInline 686 public int trueCount() { 687 return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TRUECOUNT, IntMaxMask.class, int.class, VLENGTH, this, 688 (m) -> trueCountHelper(m.getBits())); 689 } 690 691 @Override 692 @ForceInline 693 public int firstTrue() { 694 return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_FIRSTTRUE, IntMaxMask.class, int.class, VLENGTH, this, 695 (m) -> firstTrueHelper(m.getBits())); 696 } 697 698 @Override 699 @ForceInline 700 public int lastTrue() { 701 return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_LASTTRUE, IntMaxMask.class, int.class, VLENGTH, this, 702 (m) -> lastTrueHelper(m.getBits())); 703 } 704 705 @Override 706 @ForceInline 707 public long toLong() { 708 if (length() > Long.SIZE) { 709 throw new UnsupportedOperationException("too many lanes for one long"); 710 } 711 return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TOLONG, IntMaxMask.class, int.class, VLENGTH, this, 712 (m) -> toLongHelper(m.getBits())); 713 } 714 715 // Reductions 716 717 @Override 718 @ForceInline 719 public boolean anyTrue() { 720 return VectorSupport.test(BT_ne, IntMaxMask.class, int.class, VLENGTH, 721 this, vspecies().maskAll(true), 722 (m, __) -> anyTrueHelper(((IntMaxMask)m).getBits())); 723 } 724 725 @Override 726 @ForceInline 727 public boolean allTrue() { 728 return VectorSupport.test(BT_overflow, IntMaxMask.class, int.class, VLENGTH, 729 this, vspecies().maskAll(true), 730 (m, __) -> allTrueHelper(((IntMaxMask)m).getBits())); 731 } 732 733 @ForceInline 734 /*package-private*/ 735 static IntMaxMask maskAll(boolean bit) { 736 return VectorSupport.fromBitsCoerced(IntMaxMask.class, int.class, VLENGTH, 737 (bit ? -1 : 0), MODE_BROADCAST, null, 738 (v, __) -> (v != 0 ? TRUE_MASK : FALSE_MASK)); 739 } 740 private static final IntMaxMask TRUE_MASK = new IntMaxMask(true); 741 private static final IntMaxMask FALSE_MASK = new IntMaxMask(false); 742 743 744 static boolean[] maskLowerHalf() { 745 boolean[] a = new boolean[VLENGTH]; 746 int len = a.length >> 1; 747 for (int i = 0; i < len; i++) { 748 a[i] = true; 749 } 750 return a; 751 } 752 753 static final IntMaxMask LOWER_HALF_TRUE_MASK = new IntMaxMask(maskLowerHalf()); 754 } 755 756 // Shuffle 757 758 static final class IntMaxShuffle extends AbstractShuffle<Integer> { 759 static final int VLENGTH = VSPECIES.laneCount(); // used by the JVM 760 static final Class<Integer> ETYPE = int.class; // used by the JVM 761 762 IntMaxShuffle(byte[] reorder) { 763 super(VLENGTH, reorder); 764 } 765 766 public IntMaxShuffle(int[] reorder) { 767 super(VLENGTH, reorder); 768 } 769 770 public IntMaxShuffle(int[] reorder, int i) { 771 super(VLENGTH, reorder, i); 772 } 773 774 public IntMaxShuffle(IntUnaryOperator fn) { 775 super(VLENGTH, fn); 776 } 777 778 @Override 779 public IntSpecies vspecies() { 780 return VSPECIES; 781 } 782 783 static { 784 // There must be enough bits in the shuffle lanes to encode 785 // VLENGTH valid indexes and VLENGTH exceptional ones. 786 assert(VLENGTH < Byte.MAX_VALUE); 787 assert(Byte.MIN_VALUE <= -VLENGTH); 788 } 789 static final IntMaxShuffle IOTA = new IntMaxShuffle(IDENTITY); 790 791 @Override 792 @ForceInline 793 public IntMaxVector toVector() { 794 return VectorSupport.shuffleToVector(VCLASS, ETYPE, IntMaxShuffle.class, this, VLENGTH, 795 (s) -> ((IntMaxVector)(((AbstractShuffle<Integer>)(s)).toVectorTemplate()))); 796 } 797 798 @Override 799 @ForceInline 800 public <F> VectorShuffle<F> cast(VectorSpecies<F> s) { 801 AbstractSpecies<F> species = (AbstractSpecies<F>) s; 802 if (length() != species.laneCount()) 803 throw new IllegalArgumentException("VectorShuffle length and species length differ"); 804 int[] shuffleArray = toArray(); 805 return s.shuffleFromArray(shuffleArray, 0).check(s); 806 } 807 808 @ForceInline 809 @Override 810 public IntMaxShuffle rearrange(VectorShuffle<Integer> shuffle) { 811 IntMaxShuffle s = (IntMaxShuffle) shuffle; 812 byte[] reorder1 = reorder(); 813 byte[] reorder2 = s.reorder(); 814 byte[] r = new byte[reorder1.length]; 815 for (int i = 0; i < reorder1.length; i++) { 816 int ssi = reorder2[i]; 817 r[i] = reorder1[ssi]; // throws on exceptional index 818 } 819 return new IntMaxShuffle(r); 820 } 821 } 822 823 // ================================================ 824 825 // Specialized low-level memory operations. 826 827 @ForceInline 828 @Override 829 final 830 IntVector fromArray0(int[] a, int offset) { 831 return super.fromArray0Template(a, offset); // specialize 832 } 833 834 @ForceInline 835 @Override 836 final 837 IntVector fromArray0(int[] a, int offset, VectorMask<Integer> m) { 838 return super.fromArray0Template(IntMaxMask.class, a, offset, (IntMaxMask) m); // specialize 839 } 840 841 @ForceInline 842 @Override 843 final 844 IntVector fromArray0(int[] a, int offset, int[] indexMap, int mapOffset, VectorMask<Integer> m) { 845 return super.fromArray0Template(IntMaxMask.class, a, offset, indexMap, mapOffset, (IntMaxMask) m); 846 } 847 848 849 850 @ForceInline 851 @Override 852 final 853 IntVector fromByteArray0(byte[] a, int offset) { 854 return super.fromByteArray0Template(a, offset); // specialize 855 } 856 857 @ForceInline 858 @Override 859 final 860 IntVector fromByteArray0(byte[] a, int offset, VectorMask<Integer> m) { 861 return super.fromByteArray0Template(IntMaxMask.class, a, offset, (IntMaxMask) m); // specialize 862 } 863 864 @ForceInline 865 @Override 866 final 867 IntVector fromByteBuffer0(ByteBuffer bb, int offset) { 868 return super.fromByteBuffer0Template(bb, offset); // specialize 869 } 870 871 @ForceInline 872 @Override 873 final 874 IntVector fromByteBuffer0(ByteBuffer bb, int offset, VectorMask<Integer> m) { 875 return super.fromByteBuffer0Template(IntMaxMask.class, bb, offset, (IntMaxMask) m); // specialize 876 } 877 878 @ForceInline 879 @Override 880 final 881 void intoArray0(int[] a, int offset) { 882 super.intoArray0Template(a, offset); // specialize 883 } 884 885 @ForceInline 886 @Override 887 final 888 void intoArray0(int[] a, int offset, VectorMask<Integer> m) { 889 super.intoArray0Template(IntMaxMask.class, a, offset, (IntMaxMask) m); 890 } 891 892 @ForceInline 893 @Override 894 final 895 void intoArray0(int[] a, int offset, int[] indexMap, int mapOffset, VectorMask<Integer> m) { 896 super.intoArray0Template(IntMaxMask.class, a, offset, indexMap, mapOffset, (IntMaxMask) m); 897 } 898 899 900 @ForceInline 901 @Override 902 final 903 void intoByteArray0(byte[] a, int offset) { 904 super.intoByteArray0Template(a, offset); // specialize 905 } 906 907 @ForceInline 908 @Override 909 final 910 void intoByteArray0(byte[] a, int offset, VectorMask<Integer> m) { 911 super.intoByteArray0Template(IntMaxMask.class, a, offset, (IntMaxMask) m); // specialize 912 } 913 914 @ForceInline 915 @Override 916 final 917 void intoByteBuffer0(ByteBuffer bb, int offset, VectorMask<Integer> m) { 918 super.intoByteBuffer0Template(IntMaxMask.class, bb, offset, (IntMaxMask) m); 919 } 920 921 922 // End of specialized low-level memory operations. 923 924 // ================================================ 925 926 }