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 Long128Vector extends LongVector<Shapes.S128Bit> { 41 static final Long128Species SPECIES = new Long128Species(); 42 43 static final Long128Vector ZERO = new Long128Vector(); 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 Long128Vector() { 54 vec = new long[SPECIES.length()]; 55 } 56 57 Long128Vector(long[] v) { 58 vec = v; 59 } 60 61 @Override 62 public int length() { return LENGTH; } 63 64 // Unary operator 65 66 @Override 67 Long128Vector 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 Long128Vector(res); 74 } 75 76 @Override 77 Long128Vector uOp(Mask<Long, Shapes.S128Bit> o, FUnOp f) { 78 long[] vec = getElements(); 79 long[] res = new long[length()]; 80 boolean[] mbits = ((Long128Mask)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 Long128Vector(res); 85 } 86 87 // Binary operator 88 89 @Override 90 Long128Vector bOp(Vector<Long, Shapes.S128Bit> o, FBinOp f) { 91 long[] res = new long[length()]; 92 long[] vec1 = this.getElements(); 93 long[] vec2 = ((Long128Vector)o).getElements(); 94 for (int i = 0; i < length(); i++) { 95 res[i] = f.apply(i, vec1[i], vec2[i]); 96 } 97 return new Long128Vector(res); 98 } 99 100 @Override 101 Long128Vector bOp(Vector<Long, Shapes.S128Bit> o1, Mask<Long, Shapes.S128Bit> o2, FBinOp f) { 102 long[] res = new long[length()]; 103 long[] vec1 = this.getElements(); 104 long[] vec2 = ((Long128Vector)o1).getElements(); 105 boolean[] mbits = ((Long128Mask)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 Long128Vector(res); 110 } 111 112 // Trinary operator 113 114 @Override 115 Long128Vector tOp(Vector<Long, Shapes.S128Bit> o1, Vector<Long, Shapes.S128Bit> o2, FTriOp f) { 116 long[] res = new long[length()]; 117 long[] vec1 = this.getElements(); 118 long[] vec2 = ((Long128Vector)o1).getElements(); 119 long[] vec3 = ((Long128Vector)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 Long128Vector(res); 124 } 125 126 @Override 127 Long128Vector tOp(Vector<Long, Shapes.S128Bit> o1, Vector<Long, Shapes.S128Bit> o2, Mask<Long, Shapes.S128Bit> o3, FTriOp f) { 128 long[] res = new long[length()]; 129 long[] vec1 = getElements(); 130 long[] vec2 = ((Long128Vector)o1).getElements(); 131 long[] vec3 = ((Long128Vector)o2).getElements(); 132 boolean[] mbits = ((Long128Mask)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 Long128Vector(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.S128Bit> add(long o) { 153 return add(SPECIES.broadcast(o)); 154 } 155 156 @Override 157 @ForceInline 158 public LongVector<Shapes.S128Bit> add(long o, Mask<Long,Shapes.S128Bit> m) { 159 return add(SPECIES.broadcast(o), m); 160 } 161 162 @Override 163 @ForceInline 164 public LongVector<Shapes.S128Bit> sub(long o) { 165 return sub(SPECIES.broadcast(o)); 166 } 167 168 @Override 169 @ForceInline 170 public LongVector<Shapes.S128Bit> sub(long o, Mask<Long,Shapes.S128Bit> m) { 171 return sub(SPECIES.broadcast(o), m); 172 } 173 174 @Override 175 @ForceInline 176 public LongVector<Shapes.S128Bit> mul(long o) { 177 return mul(SPECIES.broadcast(o)); 178 } 179 180 @Override 181 @ForceInline 182 public LongVector<Shapes.S128Bit> mul(long o, Mask<Long,Shapes.S128Bit> m) { 183 return mul(SPECIES.broadcast(o), m); 184 } 185 186 @Override 187 @ForceInline 188 public LongVector<Shapes.S128Bit> min(long o) { 189 return min(SPECIES.broadcast(o)); 190 } 191 192 @Override 193 @ForceInline 194 public LongVector<Shapes.S128Bit> max(long o) { 195 return max(SPECIES.broadcast(o)); 196 } 197 198 @Override 199 @ForceInline 200 public Mask<Long, Shapes.S128Bit> equal(long o) { 201 return equal(SPECIES.broadcast(o)); 202 } 203 204 @Override 205 @ForceInline 206 public Mask<Long, Shapes.S128Bit> notEqual(long o) { 207 return notEqual(SPECIES.broadcast(o)); 208 } 209 210 @Override 211 @ForceInline 212 public Mask<Long, Shapes.S128Bit> lessThan(long o) { 213 return lessThan(SPECIES.broadcast(o)); 214 } 215 216 @Override 217 @ForceInline 218 public Mask<Long, Shapes.S128Bit> lessThanEq(long o) { 219 return lessThanEq(SPECIES.broadcast(o)); 220 } 221 222 @Override 223 @ForceInline 224 public Mask<Long, Shapes.S128Bit> greaterThan(long o) { 225 return greaterThan(SPECIES.broadcast(o)); 226 } 227 228 @Override 229 @ForceInline 230 public Mask<Long, Shapes.S128Bit> greaterThanEq(long o) { 231 return greaterThanEq(SPECIES.broadcast(o)); 232 } 233 234 @Override 235 @ForceInline 236 public LongVector<Shapes.S128Bit> blend(long o, Mask<Long,Shapes.S128Bit> m) { 237 return blend(SPECIES.broadcast(o), m); 238 } 239 240 241 @Override 242 @ForceInline 243 public LongVector<Shapes.S128Bit> and(long o) { 244 return and(SPECIES.broadcast(o)); 245 } 246 247 @Override 248 @ForceInline 249 public LongVector<Shapes.S128Bit> and(long o, Mask<Long,Shapes.S128Bit> m) { 250 return and(SPECIES.broadcast(o), m); 251 } 252 253 @Override 254 @ForceInline 255 public LongVector<Shapes.S128Bit> or(long o) { 256 return or(SPECIES.broadcast(o)); 257 } 258 259 @Override 260 @ForceInline 261 public LongVector<Shapes.S128Bit> or(long o, Mask<Long,Shapes.S128Bit> m) { 262 return or(SPECIES.broadcast(o), m); 263 } 264 265 @Override 266 @ForceInline 267 public LongVector<Shapes.S128Bit> xor(long o) { 268 return xor(SPECIES.broadcast(o)); 269 } 270 271 @Override 272 @ForceInline 273 public LongVector<Shapes.S128Bit> xor(long o, Mask<Long,Shapes.S128Bit> m) { 274 return xor(SPECIES.broadcast(o), m); 275 } 276 277 @Override 278 @ForceInline 279 public Long128Vector neg() { 280 return SPECIES.zero().sub(this); 281 } 282 283 // Unary operations 284 285 @ForceInline 286 @Override 287 public Long128Vector neg(Mask<Long, Shapes.S128Bit> m) { 288 return blend(neg(), m); 289 } 290 291 @Override 292 @ForceInline 293 public Long128Vector abs() { 294 return VectorIntrinsics.unaryOp( 295 VECTOR_OP_ABS, Long128Vector.class, long.class, LENGTH, 296 this, 297 v1 -> v1.uOp((i, a) -> (long) Math.abs(a))); 298 } 299 300 @ForceInline 301 @Override 302 public Long128Vector abs(Mask<Long, Shapes.S128Bit> m) { 303 return blend(abs(), m); 304 } 305 306 307 @Override 308 @ForceInline 309 public Long128Vector not() { 310 return VectorIntrinsics.unaryOp( 311 VECTOR_OP_NOT, Long128Vector.class, long.class, LENGTH, 312 this, 313 v1 -> v1.uOp((i, a) -> (long) ~a)); 314 } 315 316 @ForceInline 317 @Override 318 public Long128Vector not(Mask<Long, Shapes.S128Bit> m) { 319 return blend(not(), m); 320 } 321 // Binary operations 322 323 @Override 324 @ForceInline 325 public Long128Vector add(Vector<Long,Shapes.S128Bit> o) { 326 Objects.requireNonNull(o); 327 Long128Vector v = (Long128Vector)o; 328 return VectorIntrinsics.binaryOp( 329 VECTOR_OP_ADD, Long128Vector.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 Long128Vector add(Vector<Long,Shapes.S128Bit> v, Mask<Long, Shapes.S128Bit> m) { 337 return blend(add(v), m); 338 } 339 340 @Override 341 @ForceInline 342 public Long128Vector sub(Vector<Long,Shapes.S128Bit> o) { 343 Objects.requireNonNull(o); 344 Long128Vector v = (Long128Vector)o; 345 return VectorIntrinsics.binaryOp( 346 VECTOR_OP_SUB, Long128Vector.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 Long128Vector sub(Vector<Long,Shapes.S128Bit> v, Mask<Long, Shapes.S128Bit> m) { 354 return blend(sub(v), m); 355 } 356 357 @Override 358 @ForceInline 359 public Long128Vector mul(Vector<Long,Shapes.S128Bit> o) { 360 Objects.requireNonNull(o); 361 Long128Vector v = (Long128Vector)o; 362 return VectorIntrinsics.binaryOp( 363 VECTOR_OP_MUL, Long128Vector.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 Long128Vector mul(Vector<Long,Shapes.S128Bit> v, Mask<Long, Shapes.S128Bit> m) { 371 return blend(mul(v), m); 372 } 373 374 @Override 375 @ForceInline 376 public Long128Vector min(Vector<Long,Shapes.S128Bit> o) { 377 Objects.requireNonNull(o); 378 Long128Vector v = (Long128Vector)o; 379 return (Long128Vector) VectorIntrinsics.binaryOp( 380 VECTOR_OP_MIN, Long128Vector.class, long.class, LENGTH, 381 this, v, 382 (v1, v2) -> ((Long128Vector)v1).bOp(v2, (i, a, b) -> (long) ((a < b) ? a : b))); 383 } 384 385 @Override 386 @ForceInline 387 public Long128Vector max(Vector<Long,Shapes.S128Bit> o) { 388 Objects.requireNonNull(o); 389 Long128Vector v = (Long128Vector)o; 390 return VectorIntrinsics.binaryOp( 391 VECTOR_OP_MAX, Long128Vector.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 Long128Vector and(Vector<Long,Shapes.S128Bit> o) { 399 Objects.requireNonNull(o); 400 Long128Vector v = (Long128Vector)o; 401 return VectorIntrinsics.binaryOp( 402 VECTOR_OP_AND, Long128Vector.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 Long128Vector or(Vector<Long,Shapes.S128Bit> o) { 410 Objects.requireNonNull(o); 411 Long128Vector v = (Long128Vector)o; 412 return VectorIntrinsics.binaryOp( 413 VECTOR_OP_OR, Long128Vector.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 Long128Vector xor(Vector<Long,Shapes.S128Bit> o) { 421 Objects.requireNonNull(o); 422 Long128Vector v = (Long128Vector)o; 423 return VectorIntrinsics.binaryOp( 424 VECTOR_OP_XOR, Long128Vector.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 Long128Vector and(Vector<Long,Shapes.S128Bit> v, Mask<Long, Shapes.S128Bit> m) { 432 return blend(and(v), m); 433 } 434 435 @Override 436 @ForceInline 437 public Long128Vector or(Vector<Long,Shapes.S128Bit> v, Mask<Long, Shapes.S128Bit> m) { 438 return blend(or(v), m); 439 } 440 441 @Override 442 @ForceInline 443 public Long128Vector xor(Vector<Long,Shapes.S128Bit> v, Mask<Long, Shapes.S128Bit> m) { 444 return blend(xor(v), m); 445 } 446 447 @Override 448 @ForceInline 449 public Long128Vector shiftL(int s) { 450 return VectorIntrinsics.broadcastInt( 451 VECTOR_OP_LSHIFT, Long128Vector.class, long.class, LENGTH, 452 this, s, 453 (v, i) -> v.uOp((__, a) -> (long) (a << i))); 454 } 455 456 @Override 457 @ForceInline 458 public Long128Vector shiftR(int s) { 459 return VectorIntrinsics.broadcastInt( 460 VECTOR_OP_URSHIFT, Long128Vector.class, long.class, LENGTH, 461 this, s, 462 (v, i) -> v.uOp((__, a) -> (long) (a >>> i))); 463 } 464 465 @Override 466 @ForceInline 467 public Long128Vector aShiftR(int s) { 468 return VectorIntrinsics.broadcastInt( 469 VECTOR_OP_RSHIFT, Long128Vector.class, long.class, LENGTH, 470 this, s, 471 (v, i) -> v.uOp((__, a) -> (long) (a >> i))); 472 } 473 474 @Override 475 @ForceInline 476 public Long128Vector shiftL(Vector<Long,Shapes.S128Bit> s) { 477 Long128Vector shiftv = (Long128Vector)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, Long128Vector.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 Long128Vector shiftR(Vector<Long,Shapes.S128Bit> s) { 489 Long128Vector shiftv = (Long128Vector)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, Long128Vector.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 Long128Vector aShiftR(Vector<Long,Shapes.S128Bit> s) { 501 Long128Vector shiftv = (Long128Vector)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, Long128Vector.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, Long128Vector.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, Long128Vector.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.S128Bit> 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, Long128Vector.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, Long128Vector.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, Long128Vector.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, Long128Vector.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, Long128Vector.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.S128Bit> 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, Long128Vector.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.S128Bit> m) { 601 return blend(SPECIES.broadcast((long) 0), m).xorAll(); 602 } 603 604 605 @Override 606 @ForceInline 607 public long addAll(Mask<Long, Shapes.S128Bit> m) { 608 return blend(SPECIES.broadcast((long) 0), m).addAll(); 609 } 610 611 @Override 612 @ForceInline 613 public long subAll(Mask<Long, Shapes.S128Bit> m) { 614 return blend(SPECIES.broadcast((long) 0), m).subAll(); 615 } 616 617 @Override 618 @ForceInline 619 public long mulAll(Mask<Long, Shapes.S128Bit> m) { 620 return blend(SPECIES.broadcast((long) 1), m).mulAll(); 621 } 622 623 @Override 624 @ForceInline 625 public long minAll(Mask<Long, Shapes.S128Bit> m) { 626 return blend(SPECIES.broadcast(Long.MAX_VALUE), m).minAll(); 627 } 628 629 @Override 630 @ForceInline 631 public long maxAll(Mask<Long, Shapes.S128Bit> m) { 632 return blend(SPECIES.broadcast(Long.MIN_VALUE), m).maxAll(); 633 } 634 635 @Override 636 @ForceInline 637 public Shuffle<Long, Shapes.S128Bit> 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(Long128Vector.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.S128Bit> m) { 665 // @@@ This can result in out of bounds errors for unset mask lanes 666 Long128Vector oldVal = SPECIES.fromArray(a, ax); 667 Long128Vector 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(Long128Vector.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.S128Bit> m) { 691 // @@@ This can result in out of bounds errors for unset mask lanes 692 Long128Vector oldVal = SPECIES.fromByteArray(a, ix); 693 Long128Vector 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(Long128Vector.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.S128Bit> m) { 722 // @@@ This can result in out of bounds errors for unset mask lanes 723 Long128Vector oldVal = SPECIES.fromByteBuffer(bb, ix); 724 Long128Vector 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 Long128Vector that = (Long128Vector) 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 Long128Mask bTest(Vector<Long, Shapes.S128Bit> o, FBinTest f) { 754 long[] vec1 = getElements(); 755 long[] vec2 = ((Long128Vector)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 Long128Mask(bits); 761 } 762 763 // Comparisons 764 765 @Override 766 @ForceInline 767 public Long128Mask equal(Vector<Long, Shapes.S128Bit> o) { 768 Objects.requireNonNull(o); 769 Long128Vector v = (Long128Vector)o; 770 771 return VectorIntrinsics.compare( 772 BT_eq, Long128Vector.class, Long128Mask.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 Long128Mask notEqual(Vector<Long, Shapes.S128Bit> o) { 780 Objects.requireNonNull(o); 781 Long128Vector v = (Long128Vector)o; 782 783 return VectorIntrinsics.compare( 784 BT_ne, Long128Vector.class, Long128Mask.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 Long128Mask lessThan(Vector<Long, Shapes.S128Bit> o) { 792 Objects.requireNonNull(o); 793 Long128Vector v = (Long128Vector)o; 794 795 return VectorIntrinsics.compare( 796 BT_lt, Long128Vector.class, Long128Mask.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 Long128Mask lessThanEq(Vector<Long, Shapes.S128Bit> o) { 804 Objects.requireNonNull(o); 805 Long128Vector v = (Long128Vector)o; 806 807 return VectorIntrinsics.compare( 808 BT_le, Long128Vector.class, Long128Mask.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 Long128Mask greaterThan(Vector<Long, Shapes.S128Bit> o) { 816 Objects.requireNonNull(o); 817 Long128Vector v = (Long128Vector)o; 818 819 return (Long128Mask) VectorIntrinsics.compare( 820 BT_gt, Long128Vector.class, Long128Mask.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 Long128Mask greaterThanEq(Vector<Long, Shapes.S128Bit> o) { 828 Objects.requireNonNull(o); 829 Long128Vector v = (Long128Vector)o; 830 831 return VectorIntrinsics.compare( 832 BT_ge, Long128Vector.class, Long128Mask.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.S128Bit> o, FUnCon f) { 849 boolean[] mbits = ((Long128Mask)o).getBits(); 850 forEach((i, a) -> { 851 if (mbits[i]) { f.apply(i, a); } 852 }); 853 } 854 855 856 Double128Vector 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 Double128Vector(res); 863 } 864 865 @Override 866 public Long128Vector 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 Long128Vector(res); 873 } 874 875 @Override 876 public Long128Vector 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 Long128Vector(res); 888 } 889 890 @Override 891 public Long128Vector 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 Long128Vector(res); 898 } 899 900 @Override 901 public Long128Vector 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 Long128Vector(res); 908 } 909 910 @Override 911 @ForceInline 912 public Long128Vector rearrange(Vector<Long, Shapes.S128Bit> v, 913 Shuffle<Long, Shapes.S128Bit> s, Mask<Long, Shapes.S128Bit> m) { 914 return this.rearrange(s).blend(v.rearrange(s), m); 915 } 916 917 @Override 918 @ForceInline 919 public Long128Vector rearrange(Shuffle<Long, Shapes.S128Bit> o1) { 920 Objects.requireNonNull(o1); 921 Long128Shuffle s = (Long128Shuffle)o1; 922 923 return VectorIntrinsics.rearrangeOp( 924 Long128Vector.class, Long128Shuffle.class, long.class, LENGTH, 925 this, s, 926 (v1, s_) -> v1.uOp((i, a) -> { 927 long[] vec = this.getElements(); 928 int ei = s_.getElement(i); 929 return vec[ei]; 930 })); 931 } 932 933 @Override 934 @ForceInline 935 public Long128Vector blend(Vector<Long, Shapes.S128Bit> o1, Mask<Long, Shapes.S128Bit> o2) { 936 Objects.requireNonNull(o1); 937 Objects.requireNonNull(o2); 938 Long128Vector v = (Long128Vector)o1; 939 Long128Mask m = (Long128Mask)o2; 940 941 return VectorIntrinsics.blend( 942 Long128Vector.class, Long128Mask.class, long.class, LENGTH, 943 this, v, m, 944 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a)); 945 } 946 947 // Accessors 948 949 @Override 950 public long get(int i) { 951 if (i < 0 || i >= LENGTH) { 952 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH); 953 } 954 return (long) VectorIntrinsics.extract( 955 Long128Vector.class, long.class, LENGTH, 956 this, i, 957 (vec, ix) -> { 958 long[] vecarr = vec.getElements(); 959 return (long)vecarr[ix]; 960 }); 961 } 962 963 @Override 964 public Long128Vector with(int i, long e) { 965 if (i < 0 || i >= LENGTH) { 966 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH); 967 } 968 return VectorIntrinsics.insert( 969 Long128Vector.class, long.class, LENGTH, 970 this, i, (long)e, 971 (v, ix, bits) -> { 972 long[] res = v.getElements().clone(); 973 res[ix] = (long)bits; 974 return new Long128Vector(res); 975 }); 976 } 977 978 // Mask 979 980 static final class Long128Mask extends AbstractMask<Long, Shapes.S128Bit> { 981 static final Long128Mask TRUE_MASK = new Long128Mask(true); 982 static final Long128Mask FALSE_MASK = new Long128Mask(false); 983 984 // FIXME: was temporarily put here to simplify rematerialization support in the JVM 985 private final boolean[] bits; // Don't access directly, use getBits() instead. 986 987 public Long128Mask(boolean[] bits) { 988 this(bits, 0); 989 } 990 991 public Long128Mask(boolean[] bits, int offset) { 992 boolean[] a = new boolean[species().length()]; 993 for (int i = 0; i < a.length; i++) { 994 a[i] = bits[offset + i]; 995 } 996 this.bits = a; 997 } 998 999 public Long128Mask(boolean val) { 1000 boolean[] bits = new boolean[species().length()]; 1001 Arrays.fill(bits, val); 1002 this.bits = bits; 1003 } 1004 1005 boolean[] getBits() { 1006 return VectorIntrinsics.maybeRebox(this).bits; 1007 } 1008 1009 @Override 1010 Long128Mask uOp(MUnOp f) { 1011 boolean[] res = new boolean[species().length()]; 1012 boolean[] bits = getBits(); 1013 for (int i = 0; i < species().length(); i++) { 1014 res[i] = f.apply(i, bits[i]); 1015 } 1016 return new Long128Mask(res); 1017 } 1018 1019 @Override 1020 Long128Mask bOp(Mask<Long, Shapes.S128Bit> o, MBinOp f) { 1021 boolean[] res = new boolean[species().length()]; 1022 boolean[] bits = getBits(); 1023 boolean[] mbits = ((Long128Mask)o).getBits(); 1024 for (int i = 0; i < species().length(); i++) { 1025 res[i] = f.apply(i, bits[i], mbits[i]); 1026 } 1027 return new Long128Mask(res); 1028 } 1029 1030 @Override 1031 public Long128Species species() { 1032 return SPECIES; 1033 } 1034 1035 @Override 1036 public Long128Vector toVector() { 1037 long[] res = new long[species().length()]; 1038 boolean[] bits = getBits(); 1039 for (int i = 0; i < species().length(); i++) { 1040 // -1 will result in the most significant bit being set in 1041 // addition to some or all other bits 1042 res[i] = (long) (bits[i] ? -1 : 0); 1043 } 1044 return new Long128Vector(res); 1045 } 1046 1047 // Unary operations 1048 1049 @Override 1050 @ForceInline 1051 public Long128Mask not() { 1052 return (Long128Mask) VectorIntrinsics.unaryOp( 1053 VECTOR_OP_NOT, Long128Mask.class, long.class, LENGTH, 1054 this, 1055 (m1) -> m1.uOp((i, a) -> !a)); 1056 } 1057 1058 // Binary operations 1059 1060 @Override 1061 @ForceInline 1062 public Long128Mask and(Mask<Long,Shapes.S128Bit> o) { 1063 Objects.requireNonNull(o); 1064 Long128Mask m = (Long128Mask)o; 1065 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long128Mask.class, long.class, LENGTH, 1066 this, m, 1067 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b)); 1068 } 1069 1070 @Override 1071 @ForceInline 1072 public Long128Mask or(Mask<Long,Shapes.S128Bit> o) { 1073 Objects.requireNonNull(o); 1074 Long128Mask m = (Long128Mask)o; 1075 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Long128Mask.class, long.class, LENGTH, 1076 this, m, 1077 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b)); 1078 } 1079 1080 // Reductions 1081 1082 @Override 1083 @ForceInline 1084 public boolean anyTrue() { 1085 return VectorIntrinsics.test(COND_notZero, Long128Mask.class, long.class, LENGTH, 1086 this, this, 1087 (m1, m2) -> super.anyTrue()); 1088 } 1089 1090 @Override 1091 @ForceInline 1092 public boolean allTrue() { 1093 return VectorIntrinsics.test(COND_carrySet, Long128Mask.class, long.class, LENGTH, 1094 this, species().maskAllTrue(), 1095 (m1, m2) -> super.allTrue()); 1096 } 1097 } 1098 1099 // Shuffle 1100 1101 static final class Long128Shuffle extends AbstractShuffle<Long, Shapes.S128Bit> { 1102 Long128Shuffle(byte[] reorder) { 1103 super(reorder); 1104 } 1105 1106 public Long128Shuffle(int[] reorder) { 1107 super(reorder); 1108 } 1109 1110 public Long128Shuffle(int[] reorder, int i) { 1111 super(reorder, i); 1112 } 1113 1114 public Long128Shuffle(IntUnaryOperator f) { 1115 super(f); 1116 } 1117 1118 @Override 1119 public Long128Species species() { 1120 return SPECIES; 1121 } 1122 1123 @Override 1124 public Long128Vector toVector() { 1125 long[] va = new long[SPECIES.length()]; 1126 for (int i = 0; i < va.length; i++) { 1127 va[i] = (long) getElement(i); 1128 } 1129 return species().fromArray(va, 0); 1130 } 1131 1132 @Override 1133 public Long128Shuffle rearrange(Vector.Shuffle<Long, Shapes.S128Bit> o) { 1134 Long128Shuffle s = (Long128Shuffle) o; 1135 byte[] r = new byte[reorder.length]; 1136 for (int i = 0; i < reorder.length; i++) { 1137 r[i] = reorder[s.reorder[i]]; 1138 } 1139 return new Long128Shuffle(r); 1140 } 1141 } 1142 1143 // Species 1144 1145 @Override 1146 public Long128Species species() { 1147 return SPECIES; 1148 } 1149 1150 static final class Long128Species extends LongSpecies<Shapes.S128Bit> { 1151 static final int BIT_SIZE = Shapes.S_128_BIT.bitSize(); 1152 1153 static final int LENGTH = BIT_SIZE / Long.SIZE; 1154 1155 @Override 1156 public String toString() { 1157 StringBuilder sb = new StringBuilder("Shape["); 1158 sb.append(bitSize()).append(" bits, "); 1159 sb.append(length()).append(" ").append(long.class.getSimpleName()).append("s x "); 1160 sb.append(elementSize()).append(" bits"); 1161 sb.append("]"); 1162 return sb.toString(); 1163 } 1164 1165 @Override 1166 @ForceInline 1167 public int bitSize() { 1168 return BIT_SIZE; 1169 } 1170 1171 @Override 1172 @ForceInline 1173 public int length() { 1174 return LENGTH; 1175 } 1176 1177 @Override 1178 @ForceInline 1179 public Class<Long> elementType() { 1180 return long.class; 1181 } 1182 1183 @Override 1184 @ForceInline 1185 public int elementSize() { 1186 return Long.SIZE; 1187 } 1188 1189 @Override 1190 @ForceInline 1191 public Shapes.S128Bit shape() { 1192 return Shapes.S_128_BIT; 1193 } 1194 1195 @Override 1196 Long128Vector op(FOp f) { 1197 long[] res = new long[length()]; 1198 for (int i = 0; i < length(); i++) { 1199 res[i] = f.apply(i); 1200 } 1201 return new Long128Vector(res); 1202 } 1203 1204 @Override 1205 Long128Vector op(Mask<Long, Shapes.S128Bit> o, FOp f) { 1206 long[] res = new long[length()]; 1207 boolean[] mbits = ((Long128Mask)o).getBits(); 1208 for (int i = 0; i < length(); i++) { 1209 if (mbits[i]) { 1210 res[i] = f.apply(i); 1211 } 1212 } 1213 return new Long128Vector(res); 1214 } 1215 1216 // Factories 1217 1218 @Override 1219 public Long128Mask maskFromValues(boolean... bits) { 1220 return new Long128Mask(bits); 1221 } 1222 1223 @Override 1224 public Long128Mask maskFromArray(boolean[] bits, int i) { 1225 return new Long128Mask(bits, i); 1226 } 1227 1228 @Override 1229 public Long128Shuffle shuffle(IntUnaryOperator f) { 1230 return new Long128Shuffle(f); 1231 } 1232 1233 @Override 1234 public Long128Shuffle shuffleIota() { 1235 return new Long128Shuffle(AbstractShuffle.IDENTITY); 1236 } 1237 1238 @Override 1239 public Long128Shuffle shuffleFromValues(int... ixs) { 1240 return new Long128Shuffle(ixs); 1241 } 1242 1243 @Override 1244 public Long128Shuffle shuffleFromArray(int[] ixs, int i) { 1245 return new Long128Shuffle(ixs, i); 1246 } 1247 1248 @Override 1249 @ForceInline 1250 public Long128Vector zero() { 1251 return VectorIntrinsics.broadcastCoerced(Long128Vector.class, long.class, LENGTH, 1252 0, 1253 (z -> ZERO)); 1254 } 1255 1256 @Override 1257 @ForceInline 1258 public Long128Vector broadcast(long e) { 1259 return VectorIntrinsics.broadcastCoerced( 1260 Long128Vector.class, long.class, LENGTH, 1261 e, 1262 ((long bits) -> SPECIES.op(i -> (long)bits))); 1263 } 1264 1265 @Override 1266 @ForceInline 1267 public Long128Mask maskAllTrue() { 1268 return VectorIntrinsics.broadcastCoerced(Long128Mask.class, long.class, LENGTH, 1269 (long)-1, 1270 (z -> Long128Mask.TRUE_MASK)); 1271 } 1272 1273 @Override 1274 @ForceInline 1275 public Long128Mask maskAllFalse() { 1276 return VectorIntrinsics.broadcastCoerced(Long128Mask.class, long.class, LENGTH, 1277 0, 1278 (z -> Long128Mask.FALSE_MASK)); 1279 } 1280 1281 @Override 1282 @ForceInline 1283 public Long128Vector scalars(long... es) { 1284 Objects.requireNonNull(es); 1285 int ix = VectorIntrinsics.checkIndex(0, es.length, LENGTH); 1286 return VectorIntrinsics.load(Long128Vector.class, long.class, LENGTH, 1287 es, Unsafe.ARRAY_LONG_BASE_OFFSET, 1288 es, ix, 1289 (c, idx) -> op(n -> c[idx + n])); 1290 } 1291 1292 @Override 1293 @ForceInline 1294 public Long128Vector fromArray(long[] a, int ix) { 1295 Objects.requireNonNull(a); 1296 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH); 1297 return VectorIntrinsics.load(Long128Vector.class, long.class, LENGTH, 1298 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_LONG_BASE_OFFSET, 1299 a, ix, 1300 (c, idx) -> op(n -> c[idx + n])); 1301 } 1302 1303 @Override 1304 @ForceInline 1305 public Long128Vector fromArray(long[] a, int ax, Mask<Long, Shapes.S128Bit> m) { 1306 // @@@ This can result in out of bounds errors for unset mask lanes 1307 return zero().blend(fromArray(a, ax), m); 1308 } 1309 1310 @Override 1311 @ForceInline 1312 public Long128Vector fromByteArray(byte[] a, int ix) { 1313 // @@@ Endianess 1314 Objects.requireNonNull(a); 1315 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE); 1316 return VectorIntrinsics.load(Long128Vector.class, long.class, LENGTH, 1317 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, 1318 a, ix, 1319 (c, idx) -> { 1320 ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder()); 1321 LongBuffer tb = bbc.asLongBuffer(); 1322 return op(i -> tb.get()); 1323 }); 1324 } 1325 1326 @Override 1327 @ForceInline 1328 public Long128Vector fromByteArray(byte[] a, int ix, Mask<Long, Shapes.S128Bit> m) { 1329 // @@@ This can result in out of bounds errors for unset mask lanes 1330 return zero().blend(fromByteArray(a, ix), m); 1331 } 1332 1333 @Override 1334 @ForceInline 1335 public Long128Vector fromByteBuffer(ByteBuffer bb, int ix) { 1336 // @@@ Endianess 1337 if (bb.order() != ByteOrder.nativeOrder()) { 1338 throw new IllegalArgumentException(); 1339 } 1340 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE); 1341 return VectorIntrinsics.load(Long128Vector.class, long.class, LENGTH, 1342 U.getObject(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix, 1343 bb, ix, 1344 (c, idx) -> { 1345 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder()); 1346 LongBuffer tb = bbc.asLongBuffer(); 1347 return op(i -> tb.get()); 1348 }); 1349 } 1350 1351 @Override 1352 @ForceInline 1353 public Long128Vector fromByteBuffer(ByteBuffer bb, int ix, Mask<Long, Shapes.S128Bit> m) { 1354 // @@@ This can result in out of bounds errors for unset mask lanes 1355 return zero().blend(fromByteBuffer(bb, ix), m); 1356 } 1357 1358 @Override 1359 @ForceInline 1360 @SuppressWarnings("unchecked") 1361 public <F, T extends Shape> Long128Vector cast(Vector<F, T> o) { 1362 if (o.length() != LENGTH) 1363 throw new IllegalArgumentException("Vector length this species length differ"); 1364 1365 return VectorIntrinsics.cast( 1366 o.getClass(), 1367 o.elementType(), LENGTH, 1368 long.class, LENGTH, 1369 o, this, 1370 (s, v) -> s.castDefault(v) 1371 ); 1372 } 1373 1374 @SuppressWarnings("unchecked") 1375 @ForceInline 1376 private <F, T extends Shape> Long128Vector castDefault(Vector<F, T> v) { 1377 // Allocate array of required size 1378 int limit = length(); 1379 long[] a = new long[limit]; 1380 1381 Class<?> vtype = v.species().elementType(); 1382 if (vtype == byte.class) { 1383 ByteVector<T> tv = (ByteVector<T>)v; 1384 for (int i = 0; i < limit; i++) { 1385 a[i] = (long) tv.get(i); 1386 } 1387 } else if (vtype == short.class) { 1388 ShortVector<T> tv = (ShortVector<T>)v; 1389 for (int i = 0; i < limit; i++) { 1390 a[i] = (long) tv.get(i); 1391 } 1392 } else if (vtype == int.class) { 1393 IntVector<T> tv = (IntVector<T>)v; 1394 for (int i = 0; i < limit; i++) { 1395 a[i] = (long) tv.get(i); 1396 } 1397 } else if (vtype == long.class){ 1398 LongVector<T> tv = (LongVector<T>)v; 1399 for (int i = 0; i < limit; i++) { 1400 a[i] = (long) tv.get(i); 1401 } 1402 } else if (vtype == float.class){ 1403 FloatVector<T> tv = (FloatVector<T>)v; 1404 for (int i = 0; i < limit; i++) { 1405 a[i] = (long) tv.get(i); 1406 } 1407 } else if (vtype == double.class){ 1408 DoubleVector<T> tv = (DoubleVector<T>)v; 1409 for (int i = 0; i < limit; i++) { 1410 a[i] = (long) tv.get(i); 1411 } 1412 } else { 1413 throw new UnsupportedOperationException("Bad lane type for casting."); 1414 } 1415 1416 return scalars(a); 1417 } 1418 1419 @Override 1420 @ForceInline 1421 public <E, S extends Shape> Long128Mask cast(Mask<E, S> m) { 1422 if (m.length() != LENGTH) 1423 throw new IllegalArgumentException("Mask length this species length differ"); 1424 return new Long128Mask(m.toArray()); 1425 } 1426 1427 @Override 1428 @ForceInline 1429 public <E, S extends Shape> Long128Shuffle cast(Shuffle<E, S> s) { 1430 if (s.length() != LENGTH) 1431 throw new IllegalArgumentException("Shuffle length this species length differ"); 1432 return new Long128Shuffle(s.toArray()); 1433 } 1434 1435 @Override 1436 @ForceInline 1437 @SuppressWarnings("unchecked") 1438 public <F> Long128Vector rebracket(Vector<F, Shapes.S128Bit> o) { 1439 Objects.requireNonNull(o); 1440 if (o.elementType() == byte.class) { 1441 Byte128Vector so = (Byte128Vector)o; 1442 return VectorIntrinsics.reinterpret( 1443 Byte128Vector.class, 1444 byte.class, so.length(), 1445 long.class, LENGTH, 1446 so, this, 1447 (s, v) -> (Long128Vector) s.reshape(v) 1448 ); 1449 } else if (o.elementType() == short.class) { 1450 Short128Vector so = (Short128Vector)o; 1451 return VectorIntrinsics.reinterpret( 1452 Short128Vector.class, 1453 short.class, so.length(), 1454 long.class, LENGTH, 1455 so, this, 1456 (s, v) -> (Long128Vector) s.reshape(v) 1457 ); 1458 } else if (o.elementType() == int.class) { 1459 Int128Vector so = (Int128Vector)o; 1460 return VectorIntrinsics.reinterpret( 1461 Int128Vector.class, 1462 int.class, so.length(), 1463 long.class, LENGTH, 1464 so, this, 1465 (s, v) -> (Long128Vector) s.reshape(v) 1466 ); 1467 } else if (o.elementType() == long.class) { 1468 Long128Vector so = (Long128Vector)o; 1469 return VectorIntrinsics.reinterpret( 1470 Long128Vector.class, 1471 long.class, so.length(), 1472 long.class, LENGTH, 1473 so, this, 1474 (s, v) -> (Long128Vector) s.reshape(v) 1475 ); 1476 } else if (o.elementType() == float.class) { 1477 Float128Vector so = (Float128Vector)o; 1478 return VectorIntrinsics.reinterpret( 1479 Float128Vector.class, 1480 float.class, so.length(), 1481 long.class, LENGTH, 1482 so, this, 1483 (s, v) -> (Long128Vector) s.reshape(v) 1484 ); 1485 } else if (o.elementType() == double.class) { 1486 Double128Vector so = (Double128Vector)o; 1487 return VectorIntrinsics.reinterpret( 1488 Double128Vector.class, 1489 double.class, so.length(), 1490 long.class, LENGTH, 1491 so, this, 1492 (s, v) -> (Long128Vector) s.reshape(v) 1493 ); 1494 } else { 1495 throw new InternalError("Unimplemented type"); 1496 } 1497 } 1498 1499 @Override 1500 @ForceInline 1501 @SuppressWarnings("unchecked") 1502 public <T extends Shape> Long128Vector resize(Vector<Long, T> o) { 1503 Objects.requireNonNull(o); 1504 if (o.bitSize() == 64) { 1505 Long64Vector so = (Long64Vector)o; 1506 return VectorIntrinsics.reinterpret( 1507 Long64Vector.class, 1508 long.class, so.length(), 1509 long.class, LENGTH, 1510 so, this, 1511 (s, v) -> (Long128Vector) s.reshape(v) 1512 ); 1513 } else if (o.bitSize() == 128) { 1514 Long128Vector so = (Long128Vector)o; 1515 return VectorIntrinsics.reinterpret( 1516 Long128Vector.class, 1517 long.class, so.length(), 1518 long.class, LENGTH, 1519 so, this, 1520 (s, v) -> (Long128Vector) s.reshape(v) 1521 ); 1522 } else if (o.bitSize() == 256) { 1523 Long256Vector so = (Long256Vector)o; 1524 return VectorIntrinsics.reinterpret( 1525 Long256Vector.class, 1526 long.class, so.length(), 1527 long.class, LENGTH, 1528 so, this, 1529 (s, v) -> (Long128Vector) s.reshape(v) 1530 ); 1531 } else if (o.bitSize() == 512) { 1532 Long512Vector so = (Long512Vector)o; 1533 return VectorIntrinsics.reinterpret( 1534 Long512Vector.class, 1535 long.class, so.length(), 1536 long.class, LENGTH, 1537 so, this, 1538 (s, v) -> (Long128Vector) s.reshape(v) 1539 ); 1540 } else { 1541 throw new InternalError("Unimplemented size"); 1542 } 1543 } 1544 } 1545 }