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