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