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