1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have 23 * questions. 24 */ 25 package jdk.incubator.vector; 26 27 import java.nio.ByteBuffer; 28 import java.nio.ByteOrder; 29 import java.nio.ReadOnlyBufferException; 30 import java.util.Arrays; 31 import java.util.Objects; 32 import java.util.function.IntUnaryOperator; 33 34 import jdk.internal.misc.Unsafe; 35 import jdk.internal.vm.annotation.ForceInline; 36 import static jdk.incubator.vector.VectorIntrinsics.*; 37 38 @SuppressWarnings("cast") 39 final class Byte256Vector extends ByteVector { 40 static final Byte256Species SPECIES = new Byte256Species(); 41 42 static final Byte256Vector ZERO = new Byte256Vector(); 43 44 static final int LENGTH = SPECIES.length(); 45 46 private final byte[] vec; // Don't access directly, use getElements() instead. 47 48 private byte[] getElements() { 49 return VectorIntrinsics.maybeRebox(this).vec; 50 } 51 52 Byte256Vector() { 53 vec = new byte[SPECIES.length()]; 54 } 55 56 Byte256Vector(byte[] v) { 57 vec = v; 58 } 59 60 @Override 61 public int length() { return LENGTH; } 62 63 // Unary operator 64 65 @Override 66 Byte256Vector uOp(FUnOp f) { 67 byte[] vec = getElements(); 68 byte[] res = new byte[length()]; 69 for (int i = 0; i < length(); i++) { 70 res[i] = f.apply(i, vec[i]); 71 } 72 return new Byte256Vector(res); 73 } 74 75 @Override 76 Byte256Vector uOp(Mask<Byte> o, FUnOp f) { 77 byte[] vec = getElements(); 78 byte[] res = new byte[length()]; 79 boolean[] mbits = ((Byte256Mask)o).getBits(); 80 for (int i = 0; i < length(); i++) { 81 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i]; 82 } 83 return new Byte256Vector(res); 84 } 85 86 // Binary operator 87 88 @Override 89 Byte256Vector bOp(Vector<Byte> o, FBinOp f) { 90 byte[] res = new byte[length()]; 91 byte[] vec1 = this.getElements(); 92 byte[] vec2 = ((Byte256Vector)o).getElements(); 93 for (int i = 0; i < length(); i++) { 94 res[i] = f.apply(i, vec1[i], vec2[i]); 95 } 96 return new Byte256Vector(res); 97 } 98 99 @Override 100 Byte256Vector bOp(Vector<Byte> o1, Mask<Byte> o2, FBinOp f) { 101 byte[] res = new byte[length()]; 102 byte[] vec1 = this.getElements(); 103 byte[] vec2 = ((Byte256Vector)o1).getElements(); 104 boolean[] mbits = ((Byte256Mask)o2).getBits(); 105 for (int i = 0; i < length(); i++) { 106 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i]; 107 } 108 return new Byte256Vector(res); 109 } 110 111 // Trinary operator 112 113 @Override 114 Byte256Vector tOp(Vector<Byte> o1, Vector<Byte> o2, FTriOp f) { 115 byte[] res = new byte[length()]; 116 byte[] vec1 = this.getElements(); 117 byte[] vec2 = ((Byte256Vector)o1).getElements(); 118 byte[] vec3 = ((Byte256Vector)o2).getElements(); 119 for (int i = 0; i < length(); i++) { 120 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]); 121 } 122 return new Byte256Vector(res); 123 } 124 125 @Override 126 Byte256Vector tOp(Vector<Byte> o1, Vector<Byte> o2, Mask<Byte> o3, FTriOp f) { 127 byte[] res = new byte[length()]; 128 byte[] vec1 = getElements(); 129 byte[] vec2 = ((Byte256Vector)o1).getElements(); 130 byte[] vec3 = ((Byte256Vector)o2).getElements(); 131 boolean[] mbits = ((Byte256Mask)o3).getBits(); 132 for (int i = 0; i < length(); i++) { 133 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i]; 134 } 135 return new Byte256Vector(res); 136 } 137 138 @Override 139 byte rOp(byte v, FBinOp f) { 140 byte[] vec = getElements(); 141 for (int i = 0; i < length(); i++) { 142 v = f.apply(i, v, vec[i]); 143 } 144 return v; 145 } 146 147 @Override 148 @ForceInline 149 public <F> Vector<F> cast(Species<F> s) { 150 Objects.requireNonNull(s); 151 if (s.length() != LENGTH) 152 throw new IllegalArgumentException("Vector length this species length differ"); 153 154 return VectorIntrinsics.cast( 155 Byte256Vector.class, 156 byte.class, LENGTH, 157 s.vectorType(), 158 s.elementType(), LENGTH, 159 this, s, 160 (species, vector) -> vector.castDefault(species) 161 ); 162 } 163 164 @SuppressWarnings("unchecked") 165 @ForceInline 166 private <F> Vector<F> castDefault(Species<F> s) { 167 int limit = s.length(); 168 169 Class<?> stype = s.elementType(); 170 if (stype == byte.class) { 171 byte[] a = new byte[limit]; 172 for (int i = 0; i < limit; i++) { 173 a[i] = (byte) this.get(i); 174 } 175 return (Vector) ByteVector.fromArray((ByteVector.ByteSpecies) s, a, 0); 176 } else if (stype == short.class) { 177 short[] a = new short[limit]; 178 for (int i = 0; i < limit; i++) { 179 a[i] = (short) this.get(i); 180 } 181 return (Vector) ShortVector.fromArray((ShortVector.ShortSpecies) s, a, 0); 182 } else if (stype == int.class) { 183 int[] a = new int[limit]; 184 for (int i = 0; i < limit; i++) { 185 a[i] = (int) this.get(i); 186 } 187 return (Vector) IntVector.fromArray((IntVector.IntSpecies) s, a, 0); 188 } else if (stype == long.class) { 189 long[] a = new long[limit]; 190 for (int i = 0; i < limit; i++) { 191 a[i] = (long) this.get(i); 192 } 193 return (Vector) LongVector.fromArray((LongVector.LongSpecies) s, a, 0); 194 } else if (stype == float.class) { 195 float[] a = new float[limit]; 196 for (int i = 0; i < limit; i++) { 197 a[i] = (float) this.get(i); 198 } 199 return (Vector) FloatVector.fromArray((FloatVector.FloatSpecies) s, a, 0); 200 } else if (stype == double.class) { 201 double[] a = new double[limit]; 202 for (int i = 0; i < limit; i++) { 203 a[i] = (double) this.get(i); 204 } 205 return (Vector) DoubleVector.fromArray((DoubleVector.DoubleSpecies) s, a, 0); 206 } else { 207 throw new UnsupportedOperationException("Bad lane type for casting."); 208 } 209 } 210 211 @Override 212 @ForceInline 213 @SuppressWarnings("unchecked") 214 public <F> Vector<F> reinterpret(Species<F> s) { 215 Objects.requireNonNull(s); 216 217 if(s.elementType().equals(byte.class)) { 218 return (Vector<F>) reshape((Species<Byte>)s); 219 } 220 if(s.bitSize() == bitSize()) { 221 return reinterpretType(s); 222 } 223 224 return defaultReinterpret(s); 225 } 226 227 @ForceInline 228 private <F> Vector<F> reinterpretType(Species<F> s) { 229 Objects.requireNonNull(s); 230 231 Class<?> stype = s.elementType(); 232 if (stype == byte.class) { 233 return VectorIntrinsics.reinterpret( 234 Byte256Vector.class, 235 byte.class, LENGTH, 236 Byte256Vector.class, 237 byte.class, Byte256Vector.LENGTH, 238 this, s, 239 (species, vector) -> vector.defaultReinterpret(species) 240 ); 241 } else if (stype == short.class) { 242 return VectorIntrinsics.reinterpret( 243 Byte256Vector.class, 244 byte.class, LENGTH, 245 Short256Vector.class, 246 short.class, Short256Vector.LENGTH, 247 this, s, 248 (species, vector) -> vector.defaultReinterpret(species) 249 ); 250 } else if (stype == int.class) { 251 return VectorIntrinsics.reinterpret( 252 Byte256Vector.class, 253 byte.class, LENGTH, 254 Int256Vector.class, 255 int.class, Int256Vector.LENGTH, 256 this, s, 257 (species, vector) -> vector.defaultReinterpret(species) 258 ); 259 } else if (stype == long.class) { 260 return VectorIntrinsics.reinterpret( 261 Byte256Vector.class, 262 byte.class, LENGTH, 263 Long256Vector.class, 264 long.class, Long256Vector.LENGTH, 265 this, s, 266 (species, vector) -> vector.defaultReinterpret(species) 267 ); 268 } else if (stype == float.class) { 269 return VectorIntrinsics.reinterpret( 270 Byte256Vector.class, 271 byte.class, LENGTH, 272 Float256Vector.class, 273 float.class, Float256Vector.LENGTH, 274 this, s, 275 (species, vector) -> vector.defaultReinterpret(species) 276 ); 277 } else if (stype == double.class) { 278 return VectorIntrinsics.reinterpret( 279 Byte256Vector.class, 280 byte.class, LENGTH, 281 Double256Vector.class, 282 double.class, Double256Vector.LENGTH, 283 this, s, 284 (species, vector) -> vector.defaultReinterpret(species) 285 ); 286 } else { 287 throw new UnsupportedOperationException("Bad lane type for casting."); 288 } 289 } 290 291 @Override 292 @ForceInline 293 public ByteVector reshape(Species<Byte> s) { 294 Objects.requireNonNull(s); 295 if (s.bitSize() == 64 && (s instanceof Byte64Vector.Byte64Species)) { 296 Byte64Vector.Byte64Species ts = (Byte64Vector.Byte64Species)s; 297 return VectorIntrinsics.reinterpret( 298 Byte256Vector.class, 299 byte.class, LENGTH, 300 Byte64Vector.class, 301 byte.class, Byte64Vector.LENGTH, 302 this, ts, 303 (species, vector) -> (ByteVector) vector.defaultReinterpret(species) 304 ); 305 } else if (s.bitSize() == 128 && (s instanceof Byte128Vector.Byte128Species)) { 306 Byte128Vector.Byte128Species ts = (Byte128Vector.Byte128Species)s; 307 return VectorIntrinsics.reinterpret( 308 Byte256Vector.class, 309 byte.class, LENGTH, 310 Byte128Vector.class, 311 byte.class, Byte128Vector.LENGTH, 312 this, ts, 313 (species, vector) -> (ByteVector) vector.defaultReinterpret(species) 314 ); 315 } else if (s.bitSize() == 256 && (s instanceof Byte256Vector.Byte256Species)) { 316 Byte256Vector.Byte256Species ts = (Byte256Vector.Byte256Species)s; 317 return VectorIntrinsics.reinterpret( 318 Byte256Vector.class, 319 byte.class, LENGTH, 320 Byte256Vector.class, 321 byte.class, Byte256Vector.LENGTH, 322 this, ts, 323 (species, vector) -> (ByteVector) vector.defaultReinterpret(species) 324 ); 325 } else if (s.bitSize() == 512 && (s instanceof Byte512Vector.Byte512Species)) { 326 Byte512Vector.Byte512Species ts = (Byte512Vector.Byte512Species)s; 327 return VectorIntrinsics.reinterpret( 328 Byte256Vector.class, 329 byte.class, LENGTH, 330 Byte512Vector.class, 331 byte.class, Byte512Vector.LENGTH, 332 this, ts, 333 (species, vector) -> (ByteVector) vector.defaultReinterpret(species) 334 ); 335 } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048) 336 && (s.bitSize() % 128 == 0) && (s instanceof ByteMaxVector.ByteMaxSpecies)) { 337 ByteMaxVector.ByteMaxSpecies ts = (ByteMaxVector.ByteMaxSpecies)s; 338 return VectorIntrinsics.reinterpret( 339 Byte256Vector.class, 340 byte.class, LENGTH, 341 ByteMaxVector.class, 342 byte.class, ByteMaxVector.LENGTH, 343 this, ts, 344 (species, vector) -> (ByteVector) vector.defaultReinterpret(species) 345 ); 346 } else { 347 throw new InternalError("Unimplemented size"); 348 } 349 } 350 351 // Binary operations with scalars 352 353 @Override 354 @ForceInline 355 public ByteVector add(byte o) { 356 return add(SPECIES.broadcast(o)); 357 } 358 359 @Override 360 @ForceInline 361 public ByteVector add(byte o, Mask<Byte> m) { 362 return add(SPECIES.broadcast(o), m); 363 } 364 365 @Override 366 @ForceInline 367 public ByteVector sub(byte o) { 368 return sub(SPECIES.broadcast(o)); 369 } 370 371 @Override 372 @ForceInline 373 public ByteVector sub(byte o, Mask<Byte> m) { 374 return sub(SPECIES.broadcast(o), m); 375 } 376 377 @Override 378 @ForceInline 379 public ByteVector mul(byte o) { 380 return mul(SPECIES.broadcast(o)); 381 } 382 383 @Override 384 @ForceInline 385 public ByteVector mul(byte o, Mask<Byte> m) { 386 return mul(SPECIES.broadcast(o), m); 387 } 388 389 @Override 390 @ForceInline 391 public ByteVector min(byte o) { 392 return min(SPECIES.broadcast(o)); 393 } 394 395 @Override 396 @ForceInline 397 public ByteVector max(byte o) { 398 return max(SPECIES.broadcast(o)); 399 } 400 401 @Override 402 @ForceInline 403 public Mask<Byte> equal(byte o) { 404 return equal(SPECIES.broadcast(o)); 405 } 406 407 @Override 408 @ForceInline 409 public Mask<Byte> notEqual(byte o) { 410 return notEqual(SPECIES.broadcast(o)); 411 } 412 413 @Override 414 @ForceInline 415 public Mask<Byte> lessThan(byte o) { 416 return lessThan(SPECIES.broadcast(o)); 417 } 418 419 @Override 420 @ForceInline 421 public Mask<Byte> lessThanEq(byte o) { 422 return lessThanEq(SPECIES.broadcast(o)); 423 } 424 425 @Override 426 @ForceInline 427 public Mask<Byte> greaterThan(byte o) { 428 return greaterThan(SPECIES.broadcast(o)); 429 } 430 431 @Override 432 @ForceInline 433 public Mask<Byte> greaterThanEq(byte o) { 434 return greaterThanEq(SPECIES.broadcast(o)); 435 } 436 437 @Override 438 @ForceInline 439 public ByteVector blend(byte o, Mask<Byte> m) { 440 return blend(SPECIES.broadcast(o), m); 441 } 442 443 444 @Override 445 @ForceInline 446 public ByteVector and(byte o) { 447 return and(SPECIES.broadcast(o)); 448 } 449 450 @Override 451 @ForceInline 452 public ByteVector and(byte o, Mask<Byte> m) { 453 return and(SPECIES.broadcast(o), m); 454 } 455 456 @Override 457 @ForceInline 458 public ByteVector or(byte o) { 459 return or(SPECIES.broadcast(o)); 460 } 461 462 @Override 463 @ForceInline 464 public ByteVector or(byte o, Mask<Byte> m) { 465 return or(SPECIES.broadcast(o), m); 466 } 467 468 @Override 469 @ForceInline 470 public ByteVector xor(byte o) { 471 return xor(SPECIES.broadcast(o)); 472 } 473 474 @Override 475 @ForceInline 476 public ByteVector xor(byte o, Mask<Byte> m) { 477 return xor(SPECIES.broadcast(o), m); 478 } 479 480 @Override 481 @ForceInline 482 public Byte256Vector neg() { 483 return (Byte256Vector)zero(SPECIES).sub(this); 484 } 485 486 // Unary operations 487 488 @ForceInline 489 @Override 490 public Byte256Vector neg(Mask<Byte> m) { 491 return blend(neg(), m); 492 } 493 494 @Override 495 @ForceInline 496 public Byte256Vector abs() { 497 return VectorIntrinsics.unaryOp( 498 VECTOR_OP_ABS, Byte256Vector.class, byte.class, LENGTH, 499 this, 500 v1 -> v1.uOp((i, a) -> (byte) Math.abs(a))); 501 } 502 503 @ForceInline 504 @Override 505 public Byte256Vector abs(Mask<Byte> m) { 506 return blend(abs(), m); 507 } 508 509 510 @Override 511 @ForceInline 512 public Byte256Vector not() { 513 return VectorIntrinsics.unaryOp( 514 VECTOR_OP_NOT, Byte256Vector.class, byte.class, LENGTH, 515 this, 516 v1 -> v1.uOp((i, a) -> (byte) ~a)); 517 } 518 519 @ForceInline 520 @Override 521 public Byte256Vector not(Mask<Byte> m) { 522 return blend(not(), m); 523 } 524 // Binary operations 525 526 @Override 527 @ForceInline 528 public Byte256Vector add(Vector<Byte> o) { 529 Objects.requireNonNull(o); 530 Byte256Vector v = (Byte256Vector)o; 531 return VectorIntrinsics.binaryOp( 532 VECTOR_OP_ADD, Byte256Vector.class, byte.class, LENGTH, 533 this, v, 534 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte)(a + b))); 535 } 536 537 @Override 538 @ForceInline 539 public Byte256Vector add(Vector<Byte> v, Mask<Byte> m) { 540 return blend(add(v), m); 541 } 542 543 @Override 544 @ForceInline 545 public Byte256Vector sub(Vector<Byte> o) { 546 Objects.requireNonNull(o); 547 Byte256Vector v = (Byte256Vector)o; 548 return VectorIntrinsics.binaryOp( 549 VECTOR_OP_SUB, Byte256Vector.class, byte.class, LENGTH, 550 this, v, 551 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte)(a - b))); 552 } 553 554 @Override 555 @ForceInline 556 public Byte256Vector sub(Vector<Byte> v, Mask<Byte> m) { 557 return blend(sub(v), m); 558 } 559 560 @Override 561 @ForceInline 562 public Byte256Vector mul(Vector<Byte> o) { 563 Objects.requireNonNull(o); 564 Byte256Vector v = (Byte256Vector)o; 565 return VectorIntrinsics.binaryOp( 566 VECTOR_OP_MUL, Byte256Vector.class, byte.class, LENGTH, 567 this, v, 568 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte)(a * b))); 569 } 570 571 @Override 572 @ForceInline 573 public Byte256Vector mul(Vector<Byte> v, Mask<Byte> m) { 574 return blend(mul(v), m); 575 } 576 577 @Override 578 @ForceInline 579 public Byte256Vector min(Vector<Byte> o) { 580 Objects.requireNonNull(o); 581 Byte256Vector v = (Byte256Vector)o; 582 return (Byte256Vector) VectorIntrinsics.binaryOp( 583 VECTOR_OP_MIN, Byte256Vector.class, byte.class, LENGTH, 584 this, v, 585 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte) Math.min(a, b))); 586 } 587 588 @Override 589 @ForceInline 590 public Byte256Vector min(Vector<Byte> v, Mask<Byte> m) { 591 return blend(min(v), m); 592 } 593 594 @Override 595 @ForceInline 596 public Byte256Vector max(Vector<Byte> o) { 597 Objects.requireNonNull(o); 598 Byte256Vector v = (Byte256Vector)o; 599 return VectorIntrinsics.binaryOp( 600 VECTOR_OP_MAX, Byte256Vector.class, byte.class, LENGTH, 601 this, v, 602 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte) Math.max(a, b))); 603 } 604 605 @Override 606 @ForceInline 607 public Byte256Vector max(Vector<Byte> v, Mask<Byte> m) { 608 return blend(max(v), m); 609 } 610 611 @Override 612 @ForceInline 613 public Byte256Vector and(Vector<Byte> o) { 614 Objects.requireNonNull(o); 615 Byte256Vector v = (Byte256Vector)o; 616 return VectorIntrinsics.binaryOp( 617 VECTOR_OP_AND, Byte256Vector.class, byte.class, LENGTH, 618 this, v, 619 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte)(a & b))); 620 } 621 622 @Override 623 @ForceInline 624 public Byte256Vector or(Vector<Byte> o) { 625 Objects.requireNonNull(o); 626 Byte256Vector v = (Byte256Vector)o; 627 return VectorIntrinsics.binaryOp( 628 VECTOR_OP_OR, Byte256Vector.class, byte.class, LENGTH, 629 this, v, 630 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte)(a | b))); 631 } 632 633 @Override 634 @ForceInline 635 public Byte256Vector xor(Vector<Byte> o) { 636 Objects.requireNonNull(o); 637 Byte256Vector v = (Byte256Vector)o; 638 return VectorIntrinsics.binaryOp( 639 VECTOR_OP_XOR, Byte256Vector.class, byte.class, LENGTH, 640 this, v, 641 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (byte)(a ^ b))); 642 } 643 644 @Override 645 @ForceInline 646 public Byte256Vector and(Vector<Byte> v, Mask<Byte> m) { 647 return blend(and(v), m); 648 } 649 650 @Override 651 @ForceInline 652 public Byte256Vector or(Vector<Byte> v, Mask<Byte> m) { 653 return blend(or(v), m); 654 } 655 656 @Override 657 @ForceInline 658 public Byte256Vector xor(Vector<Byte> v, Mask<Byte> m) { 659 return blend(xor(v), m); 660 } 661 662 @Override 663 @ForceInline 664 public Byte256Vector shiftL(int s) { 665 return VectorIntrinsics.broadcastInt( 666 VECTOR_OP_LSHIFT, Byte256Vector.class, byte.class, LENGTH, 667 this, s, 668 (v, i) -> v.uOp((__, a) -> (byte) (a << (i & 7)))); 669 } 670 671 @Override 672 @ForceInline 673 public Byte256Vector shiftL(int s, Mask<Byte> m) { 674 return blend(shiftL(s), m); 675 } 676 677 @Override 678 @ForceInline 679 public Byte256Vector shiftR(int s) { 680 return VectorIntrinsics.broadcastInt( 681 VECTOR_OP_URSHIFT, Byte256Vector.class, byte.class, LENGTH, 682 this, s, 683 (v, i) -> v.uOp((__, a) -> (byte) ((a & 0xFF) >>> (i & 7)))); 684 } 685 686 @Override 687 @ForceInline 688 public Byte256Vector shiftR(int s, Mask<Byte> m) { 689 return blend(shiftR(s), m); 690 } 691 692 @Override 693 @ForceInline 694 public Byte256Vector aShiftR(int s) { 695 return VectorIntrinsics.broadcastInt( 696 VECTOR_OP_RSHIFT, Byte256Vector.class, byte.class, LENGTH, 697 this, s, 698 (v, i) -> v.uOp((__, a) -> (byte) (a >> (i & 7)))); 699 } 700 701 @Override 702 @ForceInline 703 public Byte256Vector aShiftR(int s, Mask<Byte> m) { 704 return blend(aShiftR(s), m); 705 } 706 // Ternary operations 707 708 709 // Type specific horizontal reductions 710 711 @Override 712 @ForceInline 713 public byte addAll() { 714 return (byte) VectorIntrinsics.reductionCoerced( 715 VECTOR_OP_ADD, Byte256Vector.class, byte.class, LENGTH, 716 this, 717 v -> (long) v.rOp((byte) 0, (i, a, b) -> (byte) (a + b))); 718 } 719 720 @Override 721 @ForceInline 722 public byte andAll() { 723 return (byte) VectorIntrinsics.reductionCoerced( 724 VECTOR_OP_AND, Byte256Vector.class, byte.class, LENGTH, 725 this, 726 v -> (long) v.rOp((byte) -1, (i, a, b) -> (byte) (a & b))); 727 } 728 729 @Override 730 @ForceInline 731 public byte andAll(Mask<Byte> m) { 732 return blend(SPECIES.broadcast((byte) -1), m).andAll(); 733 } 734 735 @Override 736 @ForceInline 737 public byte minAll() { 738 return (byte) VectorIntrinsics.reductionCoerced( 739 VECTOR_OP_MIN, Byte256Vector.class, byte.class, LENGTH, 740 this, 741 v -> (long) v.rOp(Byte.MAX_VALUE , (i, a, b) -> (byte) Math.min(a, b))); 742 } 743 744 @Override 745 @ForceInline 746 public byte maxAll() { 747 return (byte) VectorIntrinsics.reductionCoerced( 748 VECTOR_OP_MAX, Byte256Vector.class, byte.class, LENGTH, 749 this, 750 v -> (long) v.rOp(Byte.MIN_VALUE , (i, a, b) -> (byte) Math.max(a, b))); 751 } 752 753 @Override 754 @ForceInline 755 public byte mulAll() { 756 return (byte) VectorIntrinsics.reductionCoerced( 757 VECTOR_OP_MUL, Byte256Vector.class, byte.class, LENGTH, 758 this, 759 v -> (long) v.rOp((byte) 1, (i, a, b) -> (byte) (a * b))); 760 } 761 762 @Override 763 @ForceInline 764 public byte subAll() { 765 return (byte) VectorIntrinsics.reductionCoerced( 766 VECTOR_OP_SUB, Byte256Vector.class, byte.class, LENGTH, 767 this, 768 v -> (long) v.rOp((byte) 0, (i, a, b) -> (byte) (a - b))); 769 } 770 771 @Override 772 @ForceInline 773 public byte orAll() { 774 return (byte) VectorIntrinsics.reductionCoerced( 775 VECTOR_OP_OR, Byte256Vector.class, byte.class, LENGTH, 776 this, 777 v -> (long) v.rOp((byte) 0, (i, a, b) -> (byte) (a | b))); 778 } 779 780 @Override 781 @ForceInline 782 public byte orAll(Mask<Byte> m) { 783 return blend(SPECIES.broadcast((byte) 0), m).orAll(); 784 } 785 786 @Override 787 @ForceInline 788 public byte xorAll() { 789 return (byte) VectorIntrinsics.reductionCoerced( 790 VECTOR_OP_XOR, Byte256Vector.class, byte.class, LENGTH, 791 this, 792 v -> (long) v.rOp((byte) 0, (i, a, b) -> (byte) (a ^ b))); 793 } 794 795 @Override 796 @ForceInline 797 public byte xorAll(Mask<Byte> m) { 798 return blend(SPECIES.broadcast((byte) 0), m).xorAll(); 799 } 800 801 802 @Override 803 @ForceInline 804 public byte addAll(Mask<Byte> m) { 805 return blend(SPECIES.broadcast((byte) 0), m).addAll(); 806 } 807 808 @Override 809 @ForceInline 810 public byte subAll(Mask<Byte> m) { 811 return blend(SPECIES.broadcast((byte) 0), m).subAll(); 812 } 813 814 @Override 815 @ForceInline 816 public byte mulAll(Mask<Byte> m) { 817 return blend(SPECIES.broadcast((byte) 1), m).mulAll(); 818 } 819 820 @Override 821 @ForceInline 822 public byte minAll(Mask<Byte> m) { 823 return blend(SPECIES.broadcast(Byte.MAX_VALUE), m).minAll(); 824 } 825 826 @Override 827 @ForceInline 828 public byte maxAll(Mask<Byte> m) { 829 return blend(SPECIES.broadcast(Byte.MIN_VALUE), m).maxAll(); 830 } 831 832 @Override 833 @ForceInline 834 public Shuffle<Byte> toShuffle() { 835 byte[] a = toArray(); 836 int[] sa = new int[a.length]; 837 for (int i = 0; i < a.length; i++) { 838 sa[i] = (int) a[i]; 839 } 840 return ByteVector.shuffleFromArray(SPECIES, sa, 0); 841 } 842 843 // Memory operations 844 845 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BYTE_INDEX_SCALE); 846 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE); 847 848 @Override 849 @ForceInline 850 public void intoArray(byte[] a, int ix) { 851 Objects.requireNonNull(a); 852 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH); 853 VectorIntrinsics.store(Byte256Vector.class, byte.class, LENGTH, 854 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BYTE_BASE_OFFSET, 855 this, 856 a, ix, 857 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e)); 858 } 859 860 @Override 861 @ForceInline 862 public final void intoArray(byte[] a, int ax, Mask<Byte> m) { 863 ByteVector oldVal = ByteVector.fromArray(SPECIES, a, ax); 864 ByteVector newVal = oldVal.blend(this, m); 865 newVal.intoArray(a, ax); 866 } 867 868 @Override 869 @ForceInline 870 public void intoByteArray(byte[] a, int ix) { 871 Objects.requireNonNull(a); 872 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE); 873 VectorIntrinsics.store(Byte256Vector.class, byte.class, LENGTH, 874 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, 875 this, 876 a, ix, 877 (c, idx, v) -> { 878 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder()); 879 ByteBuffer tb = bbc; 880 v.forEach((i, e) -> tb.put(e)); 881 }); 882 } 883 884 @Override 885 @ForceInline 886 public final void intoByteArray(byte[] a, int ix, Mask<Byte> m) { 887 Byte256Vector oldVal = (Byte256Vector) ByteVector.fromByteArray(SPECIES, a, ix); 888 Byte256Vector newVal = oldVal.blend(this, m); 889 newVal.intoByteArray(a, ix); 890 } 891 892 @Override 893 @ForceInline 894 public void intoByteBuffer(ByteBuffer bb, int ix) { 895 if (bb.order() != ByteOrder.nativeOrder()) { 896 throw new IllegalArgumentException(); 897 } 898 if (bb.isReadOnly()) { 899 throw new ReadOnlyBufferException(); 900 } 901 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE); 902 VectorIntrinsics.store(Byte256Vector.class, byte.class, LENGTH, 903 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS), 904 this, 905 bb, ix, 906 (c, idx, v) -> { 907 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder()); 908 ByteBuffer tb = bbc; 909 v.forEach((i, e) -> tb.put(e)); 910 }); 911 } 912 913 @Override 914 @ForceInline 915 public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Byte> m) { 916 Byte256Vector oldVal = (Byte256Vector) ByteVector.fromByteBuffer(SPECIES, bb, ix); 917 Byte256Vector newVal = oldVal.blend(this, m); 918 newVal.intoByteBuffer(bb, ix); 919 } 920 921 // 922 923 @Override 924 public String toString() { 925 return Arrays.toString(getElements()); 926 } 927 928 @Override 929 public boolean equals(Object o) { 930 if (this == o) return true; 931 if (o == null || this.getClass() != o.getClass()) return false; 932 933 Byte256Vector that = (Byte256Vector) o; 934 return this.equal(that).allTrue(); 935 } 936 937 @Override 938 public int hashCode() { 939 return Arrays.hashCode(vec); 940 } 941 942 // Binary test 943 944 @Override 945 Byte256Mask bTest(Vector<Byte> o, FBinTest f) { 946 byte[] vec1 = getElements(); 947 byte[] vec2 = ((Byte256Vector)o).getElements(); 948 boolean[] bits = new boolean[length()]; 949 for (int i = 0; i < length(); i++){ 950 bits[i] = f.apply(i, vec1[i], vec2[i]); 951 } 952 return new Byte256Mask(bits); 953 } 954 955 // Comparisons 956 957 @Override 958 @ForceInline 959 public Byte256Mask equal(Vector<Byte> o) { 960 Objects.requireNonNull(o); 961 Byte256Vector v = (Byte256Vector)o; 962 963 return VectorIntrinsics.compare( 964 BT_eq, Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 965 this, v, 966 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a == b)); 967 } 968 969 @Override 970 @ForceInline 971 public Byte256Mask notEqual(Vector<Byte> o) { 972 Objects.requireNonNull(o); 973 Byte256Vector v = (Byte256Vector)o; 974 975 return VectorIntrinsics.compare( 976 BT_ne, Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 977 this, v, 978 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a != b)); 979 } 980 981 @Override 982 @ForceInline 983 public Byte256Mask lessThan(Vector<Byte> o) { 984 Objects.requireNonNull(o); 985 Byte256Vector v = (Byte256Vector)o; 986 987 return VectorIntrinsics.compare( 988 BT_lt, Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 989 this, v, 990 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a < b)); 991 } 992 993 @Override 994 @ForceInline 995 public Byte256Mask lessThanEq(Vector<Byte> o) { 996 Objects.requireNonNull(o); 997 Byte256Vector v = (Byte256Vector)o; 998 999 return VectorIntrinsics.compare( 1000 BT_le, Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 1001 this, v, 1002 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a <= b)); 1003 } 1004 1005 @Override 1006 @ForceInline 1007 public Byte256Mask greaterThan(Vector<Byte> o) { 1008 Objects.requireNonNull(o); 1009 Byte256Vector v = (Byte256Vector)o; 1010 1011 return (Byte256Mask) VectorIntrinsics.compare( 1012 BT_gt, Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 1013 this, v, 1014 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a > b)); 1015 } 1016 1017 @Override 1018 @ForceInline 1019 public Byte256Mask greaterThanEq(Vector<Byte> o) { 1020 Objects.requireNonNull(o); 1021 Byte256Vector v = (Byte256Vector)o; 1022 1023 return VectorIntrinsics.compare( 1024 BT_ge, Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 1025 this, v, 1026 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b)); 1027 } 1028 1029 // Foreach 1030 1031 @Override 1032 void forEach(FUnCon f) { 1033 byte[] vec = getElements(); 1034 for (int i = 0; i < length(); i++) { 1035 f.apply(i, vec[i]); 1036 } 1037 } 1038 1039 @Override 1040 void forEach(Mask<Byte> o, FUnCon f) { 1041 boolean[] mbits = ((Byte256Mask)o).getBits(); 1042 forEach((i, a) -> { 1043 if (mbits[i]) { f.apply(i, a); } 1044 }); 1045 } 1046 1047 1048 1049 @Override 1050 public Byte256Vector rotateEL(int j) { 1051 byte[] vec = getElements(); 1052 byte[] res = new byte[length()]; 1053 for (int i = 0; i < length(); i++){ 1054 res[(j + i) % length()] = vec[i]; 1055 } 1056 return new Byte256Vector(res); 1057 } 1058 1059 @Override 1060 public Byte256Vector rotateER(int j) { 1061 byte[] vec = getElements(); 1062 byte[] res = new byte[length()]; 1063 for (int i = 0; i < length(); i++){ 1064 int z = i - j; 1065 if(j < 0) { 1066 res[length() + z] = vec[i]; 1067 } else { 1068 res[z] = vec[i]; 1069 } 1070 } 1071 return new Byte256Vector(res); 1072 } 1073 1074 @Override 1075 public Byte256Vector shiftEL(int j) { 1076 byte[] vec = getElements(); 1077 byte[] res = new byte[length()]; 1078 for (int i = 0; i < length() - j; i++) { 1079 res[i] = vec[i + j]; 1080 } 1081 return new Byte256Vector(res); 1082 } 1083 1084 @Override 1085 public Byte256Vector shiftER(int j) { 1086 byte[] vec = getElements(); 1087 byte[] res = new byte[length()]; 1088 for (int i = 0; i < length() - j; i++){ 1089 res[i + j] = vec[i]; 1090 } 1091 return new Byte256Vector(res); 1092 } 1093 1094 @Override 1095 @ForceInline 1096 public Byte256Vector rearrange(Vector<Byte> v, 1097 Shuffle<Byte> s, Mask<Byte> m) { 1098 return this.rearrange(s).blend(v.rearrange(s), m); 1099 } 1100 1101 @Override 1102 @ForceInline 1103 public Byte256Vector rearrange(Shuffle<Byte> o1) { 1104 Objects.requireNonNull(o1); 1105 Byte256Shuffle s = (Byte256Shuffle)o1; 1106 1107 return VectorIntrinsics.rearrangeOp( 1108 Byte256Vector.class, Byte256Shuffle.class, byte.class, LENGTH, 1109 this, s, 1110 (v1, s_) -> v1.uOp((i, a) -> { 1111 int ei = s_.getElement(i); 1112 return v1.get(ei); 1113 })); 1114 } 1115 1116 @Override 1117 @ForceInline 1118 public Byte256Vector blend(Vector<Byte> o1, Mask<Byte> o2) { 1119 Objects.requireNonNull(o1); 1120 Objects.requireNonNull(o2); 1121 Byte256Vector v = (Byte256Vector)o1; 1122 Byte256Mask m = (Byte256Mask)o2; 1123 1124 return VectorIntrinsics.blend( 1125 Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH, 1126 this, v, m, 1127 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a)); 1128 } 1129 1130 // Accessors 1131 1132 @Override 1133 public byte get(int i) { 1134 if (i < 0 || i >= LENGTH) { 1135 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH); 1136 } 1137 return (byte) VectorIntrinsics.extract( 1138 Byte256Vector.class, byte.class, LENGTH, 1139 this, i, 1140 (vec, ix) -> { 1141 byte[] vecarr = vec.getElements(); 1142 return (long)vecarr[ix]; 1143 }); 1144 } 1145 1146 @Override 1147 public Byte256Vector with(int i, byte e) { 1148 if (i < 0 || i >= LENGTH) { 1149 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH); 1150 } 1151 return VectorIntrinsics.insert( 1152 Byte256Vector.class, byte.class, LENGTH, 1153 this, i, (long)e, 1154 (v, ix, bits) -> { 1155 byte[] res = v.getElements().clone(); 1156 res[ix] = (byte)bits; 1157 return new Byte256Vector(res); 1158 }); 1159 } 1160 1161 // Mask 1162 1163 static final class Byte256Mask extends AbstractMask<Byte> { 1164 static final Byte256Mask TRUE_MASK = new Byte256Mask(true); 1165 static final Byte256Mask FALSE_MASK = new Byte256Mask(false); 1166 1167 private final boolean[] bits; // Don't access directly, use getBits() instead. 1168 1169 public Byte256Mask(boolean[] bits) { 1170 this(bits, 0); 1171 } 1172 1173 public Byte256Mask(boolean[] bits, int offset) { 1174 boolean[] a = new boolean[species().length()]; 1175 for (int i = 0; i < a.length; i++) { 1176 a[i] = bits[offset + i]; 1177 } 1178 this.bits = a; 1179 } 1180 1181 public Byte256Mask(boolean val) { 1182 boolean[] bits = new boolean[species().length()]; 1183 Arrays.fill(bits, val); 1184 this.bits = bits; 1185 } 1186 1187 boolean[] getBits() { 1188 return VectorIntrinsics.maybeRebox(this).bits; 1189 } 1190 1191 @Override 1192 Byte256Mask uOp(MUnOp f) { 1193 boolean[] res = new boolean[species().length()]; 1194 boolean[] bits = getBits(); 1195 for (int i = 0; i < species().length(); i++) { 1196 res[i] = f.apply(i, bits[i]); 1197 } 1198 return new Byte256Mask(res); 1199 } 1200 1201 @Override 1202 Byte256Mask bOp(Mask<Byte> o, MBinOp f) { 1203 boolean[] res = new boolean[species().length()]; 1204 boolean[] bits = getBits(); 1205 boolean[] mbits = ((Byte256Mask)o).getBits(); 1206 for (int i = 0; i < species().length(); i++) { 1207 res[i] = f.apply(i, bits[i], mbits[i]); 1208 } 1209 return new Byte256Mask(res); 1210 } 1211 1212 @Override 1213 public Byte256Species species() { 1214 return SPECIES; 1215 } 1216 1217 @Override 1218 public Byte256Vector toVector() { 1219 byte[] res = new byte[species().length()]; 1220 boolean[] bits = getBits(); 1221 for (int i = 0; i < species().length(); i++) { 1222 // -1 will result in the most significant bit being set in 1223 // addition to some or all other bits 1224 res[i] = (byte) (bits[i] ? -1 : 0); 1225 } 1226 return new Byte256Vector(res); 1227 } 1228 1229 // Unary operations 1230 1231 @Override 1232 @ForceInline 1233 public Byte256Mask not() { 1234 return (Byte256Mask) VectorIntrinsics.unaryOp( 1235 VECTOR_OP_NOT, Byte256Mask.class, byte.class, LENGTH, 1236 this, 1237 (m1) -> m1.uOp((i, a) -> !a)); 1238 } 1239 1240 // Binary operations 1241 1242 @Override 1243 @ForceInline 1244 public Byte256Mask and(Mask<Byte> o) { 1245 Objects.requireNonNull(o); 1246 Byte256Mask m = (Byte256Mask)o; 1247 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Byte256Mask.class, byte.class, LENGTH, 1248 this, m, 1249 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b)); 1250 } 1251 1252 @Override 1253 @ForceInline 1254 public Byte256Mask or(Mask<Byte> o) { 1255 Objects.requireNonNull(o); 1256 Byte256Mask m = (Byte256Mask)o; 1257 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Byte256Mask.class, byte.class, LENGTH, 1258 this, m, 1259 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b)); 1260 } 1261 1262 // Reductions 1263 1264 @Override 1265 @ForceInline 1266 public boolean anyTrue() { 1267 return VectorIntrinsics.test(BT_ne, Byte256Mask.class, byte.class, LENGTH, 1268 this, this, 1269 (m, __) -> anyTrueHelper(((Byte256Mask)m).getBits())); 1270 } 1271 1272 @Override 1273 @ForceInline 1274 public boolean allTrue() { 1275 return VectorIntrinsics.test(BT_overflow, Byte256Mask.class, byte.class, LENGTH, 1276 this, ByteVector.maskAllTrue(species()), 1277 (m, __) -> allTrueHelper(((Byte256Mask)m).getBits())); 1278 } 1279 } 1280 1281 // Shuffle 1282 1283 static final class Byte256Shuffle extends AbstractShuffle<Byte> { 1284 Byte256Shuffle(byte[] reorder) { 1285 super(reorder); 1286 } 1287 1288 public Byte256Shuffle(int[] reorder) { 1289 super(reorder); 1290 } 1291 1292 public Byte256Shuffle(int[] reorder, int i) { 1293 super(reorder, i); 1294 } 1295 1296 public Byte256Shuffle(IntUnaryOperator f) { 1297 super(f); 1298 } 1299 1300 @Override 1301 public Byte256Species species() { 1302 return SPECIES; 1303 } 1304 1305 @Override 1306 public ByteVector toVector() { 1307 byte[] va = new byte[SPECIES.length()]; 1308 for (int i = 0; i < va.length; i++) { 1309 va[i] = (byte) getElement(i); 1310 } 1311 return ByteVector.fromArray(SPECIES, va, 0); 1312 } 1313 1314 @Override 1315 public Byte256Shuffle rearrange(Vector.Shuffle<Byte> o) { 1316 Byte256Shuffle s = (Byte256Shuffle) o; 1317 byte[] r = new byte[reorder.length]; 1318 for (int i = 0; i < reorder.length; i++) { 1319 r[i] = reorder[s.reorder[i]]; 1320 } 1321 return new Byte256Shuffle(r); 1322 } 1323 } 1324 1325 // Species 1326 1327 @Override 1328 public Byte256Species species() { 1329 return SPECIES; 1330 } 1331 1332 static final class Byte256Species extends ByteSpecies { 1333 static final int BIT_SIZE = Shape.S_256_BIT.bitSize(); 1334 1335 static final int LENGTH = BIT_SIZE / Byte.SIZE; 1336 1337 @Override 1338 public String toString() { 1339 StringBuilder sb = new StringBuilder("Shape["); 1340 sb.append(bitSize()).append(" bits, "); 1341 sb.append(length()).append(" ").append(byte.class.getSimpleName()).append("s x "); 1342 sb.append(elementSize()).append(" bits"); 1343 sb.append("]"); 1344 return sb.toString(); 1345 } 1346 1347 @Override 1348 @ForceInline 1349 public int bitSize() { 1350 return BIT_SIZE; 1351 } 1352 1353 @Override 1354 @ForceInline 1355 public int length() { 1356 return LENGTH; 1357 } 1358 1359 @Override 1360 @ForceInline 1361 public Class<Byte> elementType() { 1362 return byte.class; 1363 } 1364 1365 @Override 1366 @ForceInline 1367 public Class<?> boxType() { 1368 return Byte256Vector.class; 1369 } 1370 1371 @Override 1372 @ForceInline 1373 public Class<?> maskType() { 1374 return Byte256Mask.class; 1375 } 1376 1377 @Override 1378 @ForceInline 1379 public int elementSize() { 1380 return Byte.SIZE; 1381 } 1382 1383 @Override 1384 @ForceInline 1385 @SuppressWarnings("unchecked") 1386 Class<?> vectorType() { 1387 return Byte256Vector.class; 1388 } 1389 1390 @Override 1391 @ForceInline 1392 public Shape shape() { 1393 return Shape.S_256_BIT; 1394 } 1395 1396 @Override 1397 Byte256Vector op(FOp f) { 1398 byte[] res = new byte[length()]; 1399 for (int i = 0; i < length(); i++) { 1400 res[i] = f.apply(i); 1401 } 1402 return new Byte256Vector(res); 1403 } 1404 1405 @Override 1406 Byte256Vector op(Mask<Byte> o, FOp f) { 1407 byte[] res = new byte[length()]; 1408 boolean[] mbits = ((Byte256Mask)o).getBits(); 1409 for (int i = 0; i < length(); i++) { 1410 if (mbits[i]) { 1411 res[i] = f.apply(i); 1412 } 1413 } 1414 return new Byte256Vector(res); 1415 } 1416 1417 @Override 1418 Byte256Mask opm(FOpm f) { 1419 boolean[] res = new boolean[length()]; 1420 for (int i = 0; i < length(); i++) { 1421 res[i] = (boolean)f.apply(i); 1422 } 1423 return new Byte256Mask(res); 1424 } 1425 1426 // Factories 1427 1428 @Override 1429 @ForceInline 1430 public Byte256Vector zero() { 1431 return VectorIntrinsics.broadcastCoerced(Byte256Vector.class, byte.class, LENGTH, 1432 0, SPECIES, 1433 ((bits, s) -> ((Byte256Species)s).op(i -> (byte)bits))); 1434 } 1435 1436 @Override 1437 @ForceInline 1438 public Byte256Vector broadcast(byte e) { 1439 return VectorIntrinsics.broadcastCoerced( 1440 Byte256Vector.class, byte.class, LENGTH, 1441 e, SPECIES, 1442 ((bits, s) -> ((Byte256Species)s).op(i -> (byte)bits))); 1443 } 1444 1445 @Override 1446 @ForceInline 1447 public Byte256Vector scalars(byte... es) { 1448 Objects.requireNonNull(es); 1449 int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH); 1450 return VectorIntrinsics.load(Byte256Vector.class, byte.class, LENGTH, 1451 es, Unsafe.ARRAY_BYTE_BASE_OFFSET, 1452 es, ix, SPECIES, 1453 (c, idx, s) -> ((Byte256Species)s).op(n -> c[idx + n])); 1454 } 1455 1456 @Override 1457 @ForceInline 1458 public <E> Byte256Mask cast(Mask<E> m) { 1459 if (m.length() != LENGTH) 1460 throw new IllegalArgumentException("Mask length this species length differ"); 1461 return new Byte256Mask(m.toArray()); 1462 } 1463 1464 @Override 1465 @ForceInline 1466 public <E> Byte256Shuffle cast(Shuffle<E> s) { 1467 if (s.length() != LENGTH) 1468 throw new IllegalArgumentException("Shuffle length this species length differ"); 1469 return new Byte256Shuffle(s.toArray()); 1470 } 1471 } 1472 }