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