< prev index next >

test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/jdk/incubator/vector/Long256Vector.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have
  21  * questions.
  22  */
  23 
  24 package benchmark.jdk.incubator.vector;
  25 
  26 import jdk.incubator.vector.Vector;
  27 import jdk.incubator.vector.Vector.Shape;
  28 import jdk.incubator.vector.Vector.Species;

  29 import jdk.incubator.vector.LongVector;
  30 
  31 import java.util.concurrent.TimeUnit;
  32 import java.util.function.BiFunction;
  33 import java.util.function.IntFunction;
  34 
  35 import org.openjdk.jmh.annotations.*;
  36 import org.openjdk.jmh.infra.Blackhole;
  37 
  38 @BenchmarkMode(Mode.Throughput)
  39 @OutputTimeUnit(TimeUnit.MILLISECONDS)
  40 @State(Scope.Benchmark)
  41 @Warmup(iterations = 3, time = 1)
  42 @Measurement(iterations = 5, time = 1)
  43 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
  44 public class Long256Vector extends AbstractVectorBenchmark {
  45     static final Species<Long> SPECIES = LongVector.SPECIES_256;
  46 
  47     static final int INVOC_COUNT = 1; // get rid of outer loop
  48 
  49     @Param("1024")
  50     int size;
  51 
  52     long[] fill(IntFunction<Long> f) {
  53         long[] array = new long[size];
  54         for (int i = 0; i < array.length; i++) {
  55             array[i] = f.apply(i);
  56         }
  57         return array;
  58     }
  59 
  60     long[] a, b, c, r;
  61     boolean[] m, rm;
  62     int[] s;
  63 
  64     @Setup
  65     public void init() {


  91         long[] b = fb.apply(SPECIES.length());
  92         long[] r = fr.apply(SPECIES.length());
  93 
  94         for (int ic = 0; ic < INVOC_COUNT; ic++) {
  95             for (int i = 0; i < a.length; i += SPECIES.length()) {
  96                 LongVector av = LongVector.fromArray(SPECIES, a, i);
  97                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
  98                 av.add(bv).intoArray(r, i);
  99             }
 100         }
 101 
 102         bh.consume(r);
 103     }
 104 
 105     @Benchmark
 106     public void addMasked(Blackhole bh) {
 107         long[] a = fa.apply(SPECIES.length());
 108         long[] b = fb.apply(SPECIES.length());
 109         long[] r = fr.apply(SPECIES.length());
 110         boolean[] mask = fm.apply(SPECIES.length());
 111         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 112 
 113         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 114             for (int i = 0; i < a.length; i += SPECIES.length()) {
 115                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 116                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 117                 av.add(bv, vmask).intoArray(r, i);
 118             }
 119         }
 120 
 121         bh.consume(r);
 122     }
 123 
 124     @Benchmark
 125     public void sub(Blackhole bh) {
 126         long[] a = fa.apply(SPECIES.length());
 127         long[] b = fb.apply(SPECIES.length());
 128         long[] r = fr.apply(SPECIES.length());
 129 
 130         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 131             for (int i = 0; i < a.length; i += SPECIES.length()) {
 132                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 133                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 134                 av.sub(bv).intoArray(r, i);
 135             }
 136         }
 137 
 138         bh.consume(r);
 139     }
 140 
 141     @Benchmark
 142     public void subMasked(Blackhole bh) {
 143         long[] a = fa.apply(SPECIES.length());
 144         long[] b = fb.apply(SPECIES.length());
 145         long[] r = fr.apply(SPECIES.length());
 146         boolean[] mask = fm.apply(SPECIES.length());
 147         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 148 
 149         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 150             for (int i = 0; i < a.length; i += SPECIES.length()) {
 151                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 152                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 153                 av.sub(bv, vmask).intoArray(r, i);
 154             }
 155         }
 156 
 157         bh.consume(r);
 158     }
 159 
 160 
 161 
 162     @Benchmark
 163     public void mul(Blackhole bh) {
 164         long[] a = fa.apply(SPECIES.length());
 165         long[] b = fb.apply(SPECIES.length());
 166         long[] r = fr.apply(SPECIES.length());
 167 
 168         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 169             for (int i = 0; i < a.length; i += SPECIES.length()) {
 170                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 171                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 172                 av.mul(bv).intoArray(r, i);
 173             }
 174         }
 175 
 176         bh.consume(r);
 177     }
 178 
 179     @Benchmark
 180     public void mulMasked(Blackhole bh) {
 181         long[] a = fa.apply(SPECIES.length());
 182         long[] b = fb.apply(SPECIES.length());
 183         long[] r = fr.apply(SPECIES.length());
 184         boolean[] mask = fm.apply(SPECIES.length());
 185         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 186 
 187         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 188             for (int i = 0; i < a.length; i += SPECIES.length()) {
 189                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 190                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 191                 av.mul(bv, vmask).intoArray(r, i);
 192             }
 193         }
 194 
 195         bh.consume(r);
 196     }
 197 
 198 
 199     @Benchmark
 200     public void and(Blackhole bh) {
 201         long[] a = fa.apply(SPECIES.length());
 202         long[] b = fb.apply(SPECIES.length());
 203         long[] r = fr.apply(SPECIES.length());
 204 
 205         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 206             for (int i = 0; i < a.length; i += SPECIES.length()) {
 207                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 208                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 209                 av.and(bv).intoArray(r, i);
 210             }
 211         }
 212 
 213         bh.consume(r);
 214     }
 215 
 216 
 217 
 218     @Benchmark
 219     public void andMasked(Blackhole bh) {
 220         long[] a = fa.apply(SPECIES.length());
 221         long[] b = fb.apply(SPECIES.length());
 222         long[] r = fr.apply(SPECIES.length());
 223         boolean[] mask = fm.apply(SPECIES.length());
 224         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 225 
 226         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 227             for (int i = 0; i < a.length; i += SPECIES.length()) {
 228                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 229                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 230                 av.and(bv, vmask).intoArray(r, i);
 231             }
 232         }
 233 
 234         bh.consume(r);
 235     }
 236 
 237 
 238 
 239     @Benchmark
 240     public void or(Blackhole bh) {
 241         long[] a = fa.apply(SPECIES.length());
 242         long[] b = fb.apply(SPECIES.length());
 243         long[] r = fr.apply(SPECIES.length());
 244 
 245         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 246             for (int i = 0; i < a.length; i += SPECIES.length()) {
 247                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 248                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 249                 av.or(bv).intoArray(r, i);
 250             }
 251         }
 252 
 253         bh.consume(r);
 254     }
 255 
 256 
 257 
 258     @Benchmark
 259     public void orMasked(Blackhole bh) {
 260         long[] a = fa.apply(SPECIES.length());
 261         long[] b = fb.apply(SPECIES.length());
 262         long[] r = fr.apply(SPECIES.length());
 263         boolean[] mask = fm.apply(SPECIES.length());
 264         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 265 
 266         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 267             for (int i = 0; i < a.length; i += SPECIES.length()) {
 268                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 269                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 270                 av.or(bv, vmask).intoArray(r, i);
 271             }
 272         }
 273 
 274         bh.consume(r);
 275     }
 276 
 277 
 278 
 279     @Benchmark
 280     public void xor(Blackhole bh) {
 281         long[] a = fa.apply(SPECIES.length());
 282         long[] b = fb.apply(SPECIES.length());
 283         long[] r = fr.apply(SPECIES.length());
 284 
 285         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 286             for (int i = 0; i < a.length; i += SPECIES.length()) {
 287                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 288                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 289                 av.xor(bv).intoArray(r, i);
 290             }
 291         }
 292 
 293         bh.consume(r);
 294     }
 295 
 296 
 297 
 298     @Benchmark
 299     public void xorMasked(Blackhole bh) {
 300         long[] a = fa.apply(SPECIES.length());
 301         long[] b = fb.apply(SPECIES.length());
 302         long[] r = fr.apply(SPECIES.length());
 303         boolean[] mask = fm.apply(SPECIES.length());
 304         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 305 
 306         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 307             for (int i = 0; i < a.length; i += SPECIES.length()) {
 308                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 309                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 310                 av.xor(bv, vmask).intoArray(r, i);
 311             }
 312         }
 313 
 314         bh.consume(r);
 315     }
 316 
 317 
 318 
 319     @Benchmark
 320     public void shiftR(Blackhole bh) {
 321         long[] a = fa.apply(SPECIES.length());
 322         long[] b = fb.apply(SPECIES.length());
 323         long[] r = fr.apply(SPECIES.length());
 324 
 325         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 326             for (int i = 0; i < a.length; i += SPECIES.length()) {
 327                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 328                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 329                 av.shiftR(bv).intoArray(r, i);
 330             }
 331         }
 332 
 333         bh.consume(r);
 334     }
 335 
 336 
 337 
 338     @Benchmark
 339     public void shiftRMasked(Blackhole bh) {
 340         long[] a = fa.apply(SPECIES.length());
 341         long[] b = fb.apply(SPECIES.length());
 342         long[] r = fr.apply(SPECIES.length());
 343         boolean[] mask = fm.apply(SPECIES.length());
 344         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 345 
 346         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 347             for (int i = 0; i < a.length; i += SPECIES.length()) {
 348                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 349                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 350                 av.shiftR(bv, vmask).intoArray(r, i);
 351             }
 352         }
 353 
 354         bh.consume(r);
 355     }
 356 
 357 
 358 
 359     @Benchmark
 360     public void shiftL(Blackhole bh) {
 361         long[] a = fa.apply(SPECIES.length());
 362         long[] b = fb.apply(SPECIES.length());
 363         long[] r = fr.apply(SPECIES.length());
 364 
 365         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 366             for (int i = 0; i < a.length; i += SPECIES.length()) {
 367                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 368                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 369                 av.shiftL(bv).intoArray(r, i);
 370             }
 371         }
 372 
 373         bh.consume(r);
 374     }
 375 
 376 
 377 
 378     @Benchmark
 379     public void shiftLMasked(Blackhole bh) {
 380         long[] a = fa.apply(SPECIES.length());
 381         long[] b = fb.apply(SPECIES.length());
 382         long[] r = fr.apply(SPECIES.length());
 383         boolean[] mask = fm.apply(SPECIES.length());
 384         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 385 
 386         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 387             for (int i = 0; i < a.length; i += SPECIES.length()) {
 388                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 389                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 390                 av.shiftL(bv, vmask).intoArray(r, i);
 391             }
 392         }
 393 
 394         bh.consume(r);
 395     }
 396 
 397 
 398 
 399     @Benchmark
 400     public void aShiftR(Blackhole bh) {
 401         long[] a = fa.apply(SPECIES.length());
 402         long[] b = fb.apply(SPECIES.length());
 403         long[] r = fr.apply(SPECIES.length());
 404 
 405         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 406             for (int i = 0; i < a.length; i += SPECIES.length()) {
 407                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 408                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 409                 av.aShiftR(bv).intoArray(r, i);
 410             }
 411         }
 412 
 413         bh.consume(r);
 414     }
 415 
 416 
 417 
 418     @Benchmark
 419     public void aShiftRMasked(Blackhole bh) {
 420         long[] a = fa.apply(SPECIES.length());
 421         long[] b = fb.apply(SPECIES.length());
 422         long[] r = fr.apply(SPECIES.length());
 423         boolean[] mask = fm.apply(SPECIES.length());
 424         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 425 
 426         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 427             for (int i = 0; i < a.length; i += SPECIES.length()) {
 428                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 429                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 430                 av.aShiftR(bv, vmask).intoArray(r, i);
 431             }
 432         }
 433 
 434         bh.consume(r);
 435     }
 436 
 437 
 438 
 439     @Benchmark
 440     public void aShiftRShift(Blackhole bh) {
 441         long[] a = fa.apply(SPECIES.length());
 442         long[] b = fb.apply(SPECIES.length());
 443         long[] r = fr.apply(SPECIES.length());
 444 
 445         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 446             for (int i = 0; i < a.length; i += SPECIES.length()) {
 447                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 448                 av.aShiftR((int)b[i]).intoArray(r, i);
 449             }
 450         }
 451 
 452         bh.consume(r);
 453     }
 454 
 455 
 456 
 457     @Benchmark
 458     public void aShiftRMaskedShift(Blackhole bh) {
 459         long[] a = fa.apply(SPECIES.length());
 460         long[] b = fb.apply(SPECIES.length());
 461         long[] r = fr.apply(SPECIES.length());
 462         boolean[] mask = fm.apply(SPECIES.length());
 463         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 464 
 465         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 466             for (int i = 0; i < a.length; i += SPECIES.length()) {
 467                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 468                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 469             }
 470         }
 471 
 472         bh.consume(r);
 473     }
 474 
 475 
 476 
 477     @Benchmark
 478     public void shiftRShift(Blackhole bh) {
 479         long[] a = fa.apply(SPECIES.length());
 480         long[] b = fb.apply(SPECIES.length());
 481         long[] r = fr.apply(SPECIES.length());
 482 
 483         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 484             for (int i = 0; i < a.length; i += SPECIES.length()) {
 485                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 486                 av.shiftR((int)b[i]).intoArray(r, i);
 487             }
 488         }
 489 
 490         bh.consume(r);
 491     }
 492 
 493 
 494 
 495     @Benchmark
 496     public void shiftRMaskedShift(Blackhole bh) {
 497         long[] a = fa.apply(SPECIES.length());
 498         long[] b = fb.apply(SPECIES.length());
 499         long[] r = fr.apply(SPECIES.length());
 500         boolean[] mask = fm.apply(SPECIES.length());
 501         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 502 
 503         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 504             for (int i = 0; i < a.length; i += SPECIES.length()) {
 505                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 506                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 507             }
 508         }
 509 
 510         bh.consume(r);
 511     }
 512 
 513 
 514 
 515     @Benchmark
 516     public void shiftLShift(Blackhole bh) {
 517         long[] a = fa.apply(SPECIES.length());
 518         long[] b = fb.apply(SPECIES.length());
 519         long[] r = fr.apply(SPECIES.length());
 520 
 521         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 522             for (int i = 0; i < a.length; i += SPECIES.length()) {
 523                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 524                 av.shiftL((int)b[i]).intoArray(r, i);
 525             }
 526         }
 527 
 528         bh.consume(r);
 529     }
 530 
 531 
 532 
 533     @Benchmark
 534     public void shiftLMaskedShift(Blackhole bh) {
 535         long[] a = fa.apply(SPECIES.length());
 536         long[] b = fb.apply(SPECIES.length());
 537         long[] r = fr.apply(SPECIES.length());
 538         boolean[] mask = fm.apply(SPECIES.length());
 539         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 540 
 541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 542             for (int i = 0; i < a.length; i += SPECIES.length()) {
 543                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 544                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 545             }
 546         }
 547 
 548         bh.consume(r);
 549     }
 550 
 551 
 552 
 553 
 554 
 555 
 556 
 557 
 558 
 559 


 697         long ra = Long.MIN_VALUE;
 698 
 699         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 700             ra = Long.MIN_VALUE;
 701             for (int i = 0; i < a.length; i += SPECIES.length()) {
 702                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 703                 ra = (long)Math.max(ra, av.maxAll());
 704             }
 705         }
 706         bh.consume(ra);
 707     }
 708 
 709 
 710     @Benchmark
 711     public void anyTrue(Blackhole bh) {
 712         boolean[] mask = fm.apply(SPECIES.length());
 713         boolean[] r = fmr.apply(SPECIES.length());
 714 
 715         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 716             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 717                 Vector.Mask<Long> vmask = LongVector.maskFromArray(SPECIES, mask, i);
 718                 r[i] = vmask.anyTrue();
 719             }
 720         }
 721 
 722         bh.consume(r);
 723     }
 724 
 725 
 726 
 727     @Benchmark
 728     public void allTrue(Blackhole bh) {
 729         boolean[] mask = fm.apply(SPECIES.length());
 730         boolean[] r = fmr.apply(SPECIES.length());
 731 
 732         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 733             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 734                 Vector.Mask<Long> vmask = LongVector.maskFromArray(SPECIES, mask, i);
 735                 r[i] = vmask.allTrue();
 736             }
 737         }
 738 
 739         bh.consume(r);
 740     }
 741 
 742 
 743     @Benchmark
 744     public void with(Blackhole bh) {
 745         long[] a = fa.apply(SPECIES.length());
 746         long[] r = fr.apply(SPECIES.length());
 747 
 748         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 749             for (int i = 0; i < a.length; i += SPECIES.length()) {
 750                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 751                 av.with(0, (long)4).intoArray(r, i);
 752             }
 753         }
 754 
 755         bh.consume(r);
 756     }
 757 
 758     @Benchmark
 759     public Object lessThan() {
 760         long[] a = fa.apply(size);
 761         long[] b = fb.apply(size);
 762         boolean[] ms = fm.apply(size);
 763         Vector.Mask<Long> m = LongVector.maskFromArray(SPECIES, ms, 0);
 764 
 765         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 766             for (int i = 0; i < a.length; i += SPECIES.length()) {
 767                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 768                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 769                 Vector.Mask<Long> mv = av.lessThan(bv);
 770 
 771                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 772             }
 773         }
 774         return m;
 775     }
 776 
 777 
 778     @Benchmark
 779     public Object greaterThan() {
 780         long[] a = fa.apply(size);
 781         long[] b = fb.apply(size);
 782         boolean[] ms = fm.apply(size);
 783         Vector.Mask<Long> m = LongVector.maskFromArray(SPECIES, ms, 0);
 784 
 785         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 786             for (int i = 0; i < a.length; i += SPECIES.length()) {
 787                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 788                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 789                 Vector.Mask<Long> mv = av.greaterThan(bv);
 790 
 791                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 792             }
 793         }
 794         return m;
 795     }
 796 
 797 
 798     @Benchmark
 799     public Object equal() {
 800         long[] a = fa.apply(size);
 801         long[] b = fb.apply(size);
 802         boolean[] ms = fm.apply(size);
 803         Vector.Mask<Long> m = LongVector.maskFromArray(SPECIES, ms, 0);
 804 
 805         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 806             for (int i = 0; i < a.length; i += SPECIES.length()) {
 807                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 808                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 809                 Vector.Mask<Long> mv = av.equal(bv);
 810 
 811                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 812             }
 813         }
 814         return m;
 815     }
 816 
 817 
 818     @Benchmark
 819     public Object notEqual() {
 820         long[] a = fa.apply(size);
 821         long[] b = fb.apply(size);
 822         boolean[] ms = fm.apply(size);
 823         Vector.Mask<Long> m = LongVector.maskFromArray(SPECIES, ms, 0);
 824 
 825         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 826             for (int i = 0; i < a.length; i += SPECIES.length()) {
 827                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 828                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 829                 Vector.Mask<Long> mv = av.notEqual(bv);
 830 
 831                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 832             }
 833         }
 834         return m;
 835     }
 836 
 837 
 838     @Benchmark
 839     public Object lessThanEq() {
 840         long[] a = fa.apply(size);
 841         long[] b = fb.apply(size);
 842         boolean[] ms = fm.apply(size);
 843         Vector.Mask<Long> m = LongVector.maskFromArray(SPECIES, ms, 0);
 844 
 845         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 846             for (int i = 0; i < a.length; i += SPECIES.length()) {
 847                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 848                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 849                 Vector.Mask<Long> mv = av.lessThanEq(bv);
 850 
 851                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 852             }
 853         }
 854         return m;
 855     }
 856 
 857 
 858     @Benchmark
 859     public Object greaterThanEq() {
 860         long[] a = fa.apply(size);
 861         long[] b = fb.apply(size);
 862         boolean[] ms = fm.apply(size);
 863         Vector.Mask<Long> m = LongVector.maskFromArray(SPECIES, ms, 0);
 864 
 865         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 866             for (int i = 0; i < a.length; i += SPECIES.length()) {
 867                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 868                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 869                 Vector.Mask<Long> mv = av.greaterThanEq(bv);
 870 
 871                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 872             }
 873         }
 874         return m;
 875     }
 876 
 877 
 878     @Benchmark
 879     public void blend(Blackhole bh) {
 880         long[] a = fa.apply(SPECIES.length());
 881         long[] b = fb.apply(SPECIES.length());
 882         long[] r = fr.apply(SPECIES.length());
 883         boolean[] mask = fm.apply(SPECIES.length());
 884         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
 885 
 886         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 887             for (int i = 0; i < a.length; i += SPECIES.length()) {
 888                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 889                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 890                 av.blend(bv, vmask).intoArray(r, i);
 891             }
 892         }
 893 
 894         bh.consume(r);
 895     }
 896 
 897     @Benchmark
 898     public void rearrange(Blackhole bh) {
 899         long[] a = fa.apply(SPECIES.length());
 900         int[] order = fs.apply(a.length, SPECIES.length());
 901         long[] r = fr.apply(SPECIES.length());
 902 
 903         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 904             for (int i = 0; i < a.length; i += SPECIES.length()) {
 905                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 906                 av.rearrange(LongVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
 907             }
 908         }
 909 
 910         bh.consume(r);
 911     }
 912 
 913     @Benchmark
 914     public void extract(Blackhole bh) {
 915         long[] a = fa.apply(SPECIES.length());
 916         long[] r = fr.apply(SPECIES.length());
 917 
 918         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 919             for (int i = 0; i < a.length; i += SPECIES.length()) {
 920                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 921                 int num_lanes = SPECIES.length();
 922                 // Manually unroll because full unroll happens after intrinsification.
 923                 // Unroll is needed because get intrinsic requires for index to be a known constant.
 924                 if (num_lanes == 1) {
 925                     r[i]=av.get(0);
 926                 } else if (num_lanes == 2) {


1089     @Benchmark
1090     public void neg(Blackhole bh) {
1091         long[] a = fa.apply(SPECIES.length());
1092         long[] r = fr.apply(SPECIES.length());
1093 
1094         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1095             for (int i = 0; i < a.length; i += SPECIES.length()) {
1096                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1097                 av.neg().intoArray(r, i);
1098             }
1099         }
1100 
1101         bh.consume(r);
1102     }
1103 
1104     @Benchmark
1105     public void negMasked(Blackhole bh) {
1106         long[] a = fa.apply(SPECIES.length());
1107         long[] r = fr.apply(SPECIES.length());
1108         boolean[] mask = fm.apply(SPECIES.length());
1109         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
1110 
1111         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1112             for (int i = 0; i < a.length; i += SPECIES.length()) {
1113                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1114                 av.neg(vmask).intoArray(r, i);
1115             }
1116         }
1117 
1118         bh.consume(r);
1119     }
1120 
1121     @Benchmark
1122     public void abs(Blackhole bh) {
1123         long[] a = fa.apply(SPECIES.length());
1124         long[] r = fr.apply(SPECIES.length());
1125 
1126         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1127             for (int i = 0; i < a.length; i += SPECIES.length()) {
1128                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1129                 av.abs().intoArray(r, i);
1130             }
1131         }
1132 
1133         bh.consume(r);
1134     }
1135 
1136     @Benchmark
1137     public void absMasked(Blackhole bh) {
1138         long[] a = fa.apply(SPECIES.length());
1139         long[] r = fr.apply(SPECIES.length());
1140         boolean[] mask = fm.apply(SPECIES.length());
1141         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
1142 
1143         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1144             for (int i = 0; i < a.length; i += SPECIES.length()) {
1145                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1146                 av.abs(vmask).intoArray(r, i);
1147             }
1148         }
1149 
1150         bh.consume(r);
1151     }
1152 
1153 
1154     @Benchmark
1155     public void not(Blackhole bh) {
1156         long[] a = fa.apply(SPECIES.length());
1157         long[] r = fr.apply(SPECIES.length());
1158 
1159         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1160             for (int i = 0; i < a.length; i += SPECIES.length()) {
1161                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1162                 av.not().intoArray(r, i);
1163             }
1164         }
1165 
1166         bh.consume(r);
1167     }
1168 
1169 
1170 
1171     @Benchmark
1172     public void notMasked(Blackhole bh) {
1173         long[] a = fa.apply(SPECIES.length());
1174         long[] r = fr.apply(SPECIES.length());
1175         boolean[] mask = fm.apply(SPECIES.length());
1176         Vector.Mask<Long> vmask = LongVector.maskFromValues(SPECIES, mask);
1177 
1178         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1179             for (int i = 0; i < a.length; i += SPECIES.length()) {
1180                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1181                 av.not(vmask).intoArray(r, i);
1182             }
1183         }
1184 
1185         bh.consume(r);
1186     }
1187 
1188 
1189 
1190 
1191 
1192     @Benchmark
1193     public void gather(Blackhole bh) {
1194         long[] a = fa.apply(SPECIES.length());
1195         int[] b    = fs.apply(a.length, SPECIES.length());
1196         long[] r = new long[a.length];




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have
  21  * questions.
  22  */
  23 
  24 package benchmark.jdk.incubator.vector;
  25 
  26 import jdk.incubator.vector.Vector;
  27 import jdk.incubator.vector.VectorShape;
  28 import jdk.incubator.vector.VectorSpecies;
  29 import jdk.incubator.vector.VectorShuffle;
  30 import jdk.incubator.vector.LongVector;
  31 
  32 import java.util.concurrent.TimeUnit;
  33 import java.util.function.BiFunction;
  34 import java.util.function.IntFunction;
  35 
  36 import org.openjdk.jmh.annotations.*;
  37 import org.openjdk.jmh.infra.Blackhole;
  38 
  39 @BenchmarkMode(Mode.Throughput)
  40 @OutputTimeUnit(TimeUnit.MILLISECONDS)
  41 @State(Scope.Benchmark)
  42 @Warmup(iterations = 3, time = 1)
  43 @Measurement(iterations = 5, time = 1)
  44 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
  45 public class Long256Vector extends AbstractVectorBenchmark {
  46     static final VectorSpecies<Long> SPECIES = LongVector.SPECIES_256;
  47 
  48     static final int INVOC_COUNT = 1; // get rid of outer loop
  49 
  50     @Param("1024")
  51     int size;
  52 
  53     long[] fill(IntFunction<Long> f) {
  54         long[] array = new long[size];
  55         for (int i = 0; i < array.length; i++) {
  56             array[i] = f.apply(i);
  57         }
  58         return array;
  59     }
  60 
  61     long[] a, b, c, r;
  62     boolean[] m, rm;
  63     int[] s;
  64 
  65     @Setup
  66     public void init() {


  92         long[] b = fb.apply(SPECIES.length());
  93         long[] r = fr.apply(SPECIES.length());
  94 
  95         for (int ic = 0; ic < INVOC_COUNT; ic++) {
  96             for (int i = 0; i < a.length; i += SPECIES.length()) {
  97                 LongVector av = LongVector.fromArray(SPECIES, a, i);
  98                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
  99                 av.add(bv).intoArray(r, i);
 100             }
 101         }
 102 
 103         bh.consume(r);
 104     }
 105 
 106     @Benchmark
 107     public void addMasked(Blackhole bh) {
 108         long[] a = fa.apply(SPECIES.length());
 109         long[] b = fb.apply(SPECIES.length());
 110         long[] r = fr.apply(SPECIES.length());
 111         boolean[] mask = fm.apply(SPECIES.length());
 112         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 113 
 114         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 115             for (int i = 0; i < a.length; i += SPECIES.length()) {
 116                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 117                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 118                 av.add(bv, vmask).intoArray(r, i);
 119             }
 120         }
 121 
 122         bh.consume(r);
 123     }
 124 
 125     @Benchmark
 126     public void sub(Blackhole bh) {
 127         long[] a = fa.apply(SPECIES.length());
 128         long[] b = fb.apply(SPECIES.length());
 129         long[] r = fr.apply(SPECIES.length());
 130 
 131         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 132             for (int i = 0; i < a.length; i += SPECIES.length()) {
 133                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 134                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 135                 av.sub(bv).intoArray(r, i);
 136             }
 137         }
 138 
 139         bh.consume(r);
 140     }
 141 
 142     @Benchmark
 143     public void subMasked(Blackhole bh) {
 144         long[] a = fa.apply(SPECIES.length());
 145         long[] b = fb.apply(SPECIES.length());
 146         long[] r = fr.apply(SPECIES.length());
 147         boolean[] mask = fm.apply(SPECIES.length());
 148         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 149 
 150         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 151             for (int i = 0; i < a.length; i += SPECIES.length()) {
 152                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 153                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 154                 av.sub(bv, vmask).intoArray(r, i);
 155             }
 156         }
 157 
 158         bh.consume(r);
 159     }
 160 
 161 
 162 
 163     @Benchmark
 164     public void mul(Blackhole bh) {
 165         long[] a = fa.apply(SPECIES.length());
 166         long[] b = fb.apply(SPECIES.length());
 167         long[] r = fr.apply(SPECIES.length());
 168 
 169         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 170             for (int i = 0; i < a.length; i += SPECIES.length()) {
 171                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 172                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 173                 av.mul(bv).intoArray(r, i);
 174             }
 175         }
 176 
 177         bh.consume(r);
 178     }
 179 
 180     @Benchmark
 181     public void mulMasked(Blackhole bh) {
 182         long[] a = fa.apply(SPECIES.length());
 183         long[] b = fb.apply(SPECIES.length());
 184         long[] r = fr.apply(SPECIES.length());
 185         boolean[] mask = fm.apply(SPECIES.length());
 186         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 187 
 188         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 189             for (int i = 0; i < a.length; i += SPECIES.length()) {
 190                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 191                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 192                 av.mul(bv, vmask).intoArray(r, i);
 193             }
 194         }
 195 
 196         bh.consume(r);
 197     }
 198 
 199 
 200     @Benchmark
 201     public void and(Blackhole bh) {
 202         long[] a = fa.apply(SPECIES.length());
 203         long[] b = fb.apply(SPECIES.length());
 204         long[] r = fr.apply(SPECIES.length());
 205 
 206         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 207             for (int i = 0; i < a.length; i += SPECIES.length()) {
 208                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 209                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 210                 av.and(bv).intoArray(r, i);
 211             }
 212         }
 213 
 214         bh.consume(r);
 215     }
 216 
 217 
 218 
 219     @Benchmark
 220     public void andMasked(Blackhole bh) {
 221         long[] a = fa.apply(SPECIES.length());
 222         long[] b = fb.apply(SPECIES.length());
 223         long[] r = fr.apply(SPECIES.length());
 224         boolean[] mask = fm.apply(SPECIES.length());
 225         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 226 
 227         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 228             for (int i = 0; i < a.length; i += SPECIES.length()) {
 229                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 230                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 231                 av.and(bv, vmask).intoArray(r, i);
 232             }
 233         }
 234 
 235         bh.consume(r);
 236     }
 237 
 238 
 239 
 240     @Benchmark
 241     public void or(Blackhole bh) {
 242         long[] a = fa.apply(SPECIES.length());
 243         long[] b = fb.apply(SPECIES.length());
 244         long[] r = fr.apply(SPECIES.length());
 245 
 246         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 247             for (int i = 0; i < a.length; i += SPECIES.length()) {
 248                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 249                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 250                 av.or(bv).intoArray(r, i);
 251             }
 252         }
 253 
 254         bh.consume(r);
 255     }
 256 
 257 
 258 
 259     @Benchmark
 260     public void orMasked(Blackhole bh) {
 261         long[] a = fa.apply(SPECIES.length());
 262         long[] b = fb.apply(SPECIES.length());
 263         long[] r = fr.apply(SPECIES.length());
 264         boolean[] mask = fm.apply(SPECIES.length());
 265         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 266 
 267         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 268             for (int i = 0; i < a.length; i += SPECIES.length()) {
 269                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 270                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 271                 av.or(bv, vmask).intoArray(r, i);
 272             }
 273         }
 274 
 275         bh.consume(r);
 276     }
 277 
 278 
 279 
 280     @Benchmark
 281     public void xor(Blackhole bh) {
 282         long[] a = fa.apply(SPECIES.length());
 283         long[] b = fb.apply(SPECIES.length());
 284         long[] r = fr.apply(SPECIES.length());
 285 
 286         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 287             for (int i = 0; i < a.length; i += SPECIES.length()) {
 288                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 289                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 290                 av.xor(bv).intoArray(r, i);
 291             }
 292         }
 293 
 294         bh.consume(r);
 295     }
 296 
 297 
 298 
 299     @Benchmark
 300     public void xorMasked(Blackhole bh) {
 301         long[] a = fa.apply(SPECIES.length());
 302         long[] b = fb.apply(SPECIES.length());
 303         long[] r = fr.apply(SPECIES.length());
 304         boolean[] mask = fm.apply(SPECIES.length());
 305         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 306 
 307         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 308             for (int i = 0; i < a.length; i += SPECIES.length()) {
 309                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 310                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 311                 av.xor(bv, vmask).intoArray(r, i);
 312             }
 313         }
 314 
 315         bh.consume(r);
 316     }
 317 
 318 
 319 
 320     @Benchmark
 321     public void shiftR(Blackhole bh) {
 322         long[] a = fa.apply(SPECIES.length());
 323         long[] b = fb.apply(SPECIES.length());
 324         long[] r = fr.apply(SPECIES.length());
 325 
 326         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 327             for (int i = 0; i < a.length; i += SPECIES.length()) {
 328                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 329                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 330                 av.shiftR(bv).intoArray(r, i);
 331             }
 332         }
 333 
 334         bh.consume(r);
 335     }
 336 
 337 
 338 
 339     @Benchmark
 340     public void shiftRMasked(Blackhole bh) {
 341         long[] a = fa.apply(SPECIES.length());
 342         long[] b = fb.apply(SPECIES.length());
 343         long[] r = fr.apply(SPECIES.length());
 344         boolean[] mask = fm.apply(SPECIES.length());
 345         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 346 
 347         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 348             for (int i = 0; i < a.length; i += SPECIES.length()) {
 349                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 350                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 351                 av.shiftR(bv, vmask).intoArray(r, i);
 352             }
 353         }
 354 
 355         bh.consume(r);
 356     }
 357 
 358 
 359 
 360     @Benchmark
 361     public void shiftL(Blackhole bh) {
 362         long[] a = fa.apply(SPECIES.length());
 363         long[] b = fb.apply(SPECIES.length());
 364         long[] r = fr.apply(SPECIES.length());
 365 
 366         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 367             for (int i = 0; i < a.length; i += SPECIES.length()) {
 368                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 369                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 370                 av.shiftL(bv).intoArray(r, i);
 371             }
 372         }
 373 
 374         bh.consume(r);
 375     }
 376 
 377 
 378 
 379     @Benchmark
 380     public void shiftLMasked(Blackhole bh) {
 381         long[] a = fa.apply(SPECIES.length());
 382         long[] b = fb.apply(SPECIES.length());
 383         long[] r = fr.apply(SPECIES.length());
 384         boolean[] mask = fm.apply(SPECIES.length());
 385         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 386 
 387         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 388             for (int i = 0; i < a.length; i += SPECIES.length()) {
 389                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 390                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 391                 av.shiftL(bv, vmask).intoArray(r, i);
 392             }
 393         }
 394 
 395         bh.consume(r);
 396     }
 397 
 398 
 399 
 400     @Benchmark
 401     public void aShiftR(Blackhole bh) {
 402         long[] a = fa.apply(SPECIES.length());
 403         long[] b = fb.apply(SPECIES.length());
 404         long[] r = fr.apply(SPECIES.length());
 405 
 406         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 407             for (int i = 0; i < a.length; i += SPECIES.length()) {
 408                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 409                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 410                 av.aShiftR(bv).intoArray(r, i);
 411             }
 412         }
 413 
 414         bh.consume(r);
 415     }
 416 
 417 
 418 
 419     @Benchmark
 420     public void aShiftRMasked(Blackhole bh) {
 421         long[] a = fa.apply(SPECIES.length());
 422         long[] b = fb.apply(SPECIES.length());
 423         long[] r = fr.apply(SPECIES.length());
 424         boolean[] mask = fm.apply(SPECIES.length());
 425         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 426 
 427         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 428             for (int i = 0; i < a.length; i += SPECIES.length()) {
 429                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 430                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 431                 av.aShiftR(bv, vmask).intoArray(r, i);
 432             }
 433         }
 434 
 435         bh.consume(r);
 436     }
 437 
 438 
 439 
 440     @Benchmark
 441     public void aShiftRShift(Blackhole bh) {
 442         long[] a = fa.apply(SPECIES.length());
 443         long[] b = fb.apply(SPECIES.length());
 444         long[] r = fr.apply(SPECIES.length());
 445 
 446         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 447             for (int i = 0; i < a.length; i += SPECIES.length()) {
 448                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 449                 av.aShiftR((int)b[i]).intoArray(r, i);
 450             }
 451         }
 452 
 453         bh.consume(r);
 454     }
 455 
 456 
 457 
 458     @Benchmark
 459     public void aShiftRMaskedShift(Blackhole bh) {
 460         long[] a = fa.apply(SPECIES.length());
 461         long[] b = fb.apply(SPECIES.length());
 462         long[] r = fr.apply(SPECIES.length());
 463         boolean[] mask = fm.apply(SPECIES.length());
 464         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 465 
 466         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 467             for (int i = 0; i < a.length; i += SPECIES.length()) {
 468                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 469                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 470             }
 471         }
 472 
 473         bh.consume(r);
 474     }
 475 
 476 
 477 
 478     @Benchmark
 479     public void shiftRShift(Blackhole bh) {
 480         long[] a = fa.apply(SPECIES.length());
 481         long[] b = fb.apply(SPECIES.length());
 482         long[] r = fr.apply(SPECIES.length());
 483 
 484         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 485             for (int i = 0; i < a.length; i += SPECIES.length()) {
 486                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 487                 av.shiftR((int)b[i]).intoArray(r, i);
 488             }
 489         }
 490 
 491         bh.consume(r);
 492     }
 493 
 494 
 495 
 496     @Benchmark
 497     public void shiftRMaskedShift(Blackhole bh) {
 498         long[] a = fa.apply(SPECIES.length());
 499         long[] b = fb.apply(SPECIES.length());
 500         long[] r = fr.apply(SPECIES.length());
 501         boolean[] mask = fm.apply(SPECIES.length());
 502         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 503 
 504         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 505             for (int i = 0; i < a.length; i += SPECIES.length()) {
 506                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 507                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 508             }
 509         }
 510 
 511         bh.consume(r);
 512     }
 513 
 514 
 515 
 516     @Benchmark
 517     public void shiftLShift(Blackhole bh) {
 518         long[] a = fa.apply(SPECIES.length());
 519         long[] b = fb.apply(SPECIES.length());
 520         long[] r = fr.apply(SPECIES.length());
 521 
 522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 523             for (int i = 0; i < a.length; i += SPECIES.length()) {
 524                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 525                 av.shiftL((int)b[i]).intoArray(r, i);
 526             }
 527         }
 528 
 529         bh.consume(r);
 530     }
 531 
 532 
 533 
 534     @Benchmark
 535     public void shiftLMaskedShift(Blackhole bh) {
 536         long[] a = fa.apply(SPECIES.length());
 537         long[] b = fb.apply(SPECIES.length());
 538         long[] r = fr.apply(SPECIES.length());
 539         boolean[] mask = fm.apply(SPECIES.length());
 540         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 541 
 542         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 543             for (int i = 0; i < a.length; i += SPECIES.length()) {
 544                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 545                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 546             }
 547         }
 548 
 549         bh.consume(r);
 550     }
 551 
 552 
 553 
 554 
 555 
 556 
 557 
 558 
 559 
 560 


 698         long ra = Long.MIN_VALUE;
 699 
 700         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 701             ra = Long.MIN_VALUE;
 702             for (int i = 0; i < a.length; i += SPECIES.length()) {
 703                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 704                 ra = (long)Math.max(ra, av.maxAll());
 705             }
 706         }
 707         bh.consume(ra);
 708     }
 709 
 710 
 711     @Benchmark
 712     public void anyTrue(Blackhole bh) {
 713         boolean[] mask = fm.apply(SPECIES.length());
 714         boolean[] r = fmr.apply(SPECIES.length());
 715 
 716         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 717             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 718                 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, i);
 719                 r[i] = vmask.anyTrue();
 720             }
 721         }
 722 
 723         bh.consume(r);
 724     }
 725 
 726 
 727 
 728     @Benchmark
 729     public void allTrue(Blackhole bh) {
 730         boolean[] mask = fm.apply(SPECIES.length());
 731         boolean[] r = fmr.apply(SPECIES.length());
 732 
 733         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 734             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 735                 VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, i);
 736                 r[i] = vmask.allTrue();
 737             }
 738         }
 739 
 740         bh.consume(r);
 741     }
 742 
 743 
 744     @Benchmark
 745     public void with(Blackhole bh) {
 746         long[] a = fa.apply(SPECIES.length());
 747         long[] r = fr.apply(SPECIES.length());
 748 
 749         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 750             for (int i = 0; i < a.length; i += SPECIES.length()) {
 751                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 752                 av.with(0, (long)4).intoArray(r, i);
 753             }
 754         }
 755 
 756         bh.consume(r);
 757     }
 758 
 759     @Benchmark
 760     public Object lessThan() {
 761         long[] a = fa.apply(size);
 762         long[] b = fb.apply(size);
 763         boolean[] ms = fm.apply(size);
 764         VectorMask<Long> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 765 
 766         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 767             for (int i = 0; i < a.length; i += SPECIES.length()) {
 768                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 769                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 770                 VectorMask<Long> mv = av.lessThan(bv);
 771 
 772                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 773             }
 774         }
 775         return m;
 776     }
 777 
 778 
 779     @Benchmark
 780     public Object greaterThan() {
 781         long[] a = fa.apply(size);
 782         long[] b = fb.apply(size);
 783         boolean[] ms = fm.apply(size);
 784         VectorMask<Long> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 785 
 786         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 787             for (int i = 0; i < a.length; i += SPECIES.length()) {
 788                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 789                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 790                 VectorMask<Long> mv = av.greaterThan(bv);
 791 
 792                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 793             }
 794         }
 795         return m;
 796     }
 797 
 798 
 799     @Benchmark
 800     public Object equal() {
 801         long[] a = fa.apply(size);
 802         long[] b = fb.apply(size);
 803         boolean[] ms = fm.apply(size);
 804         VectorMask<Long> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 805 
 806         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 807             for (int i = 0; i < a.length; i += SPECIES.length()) {
 808                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 809                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 810                 VectorMask<Long> mv = av.equal(bv);
 811 
 812                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 813             }
 814         }
 815         return m;
 816     }
 817 
 818 
 819     @Benchmark
 820     public Object notEqual() {
 821         long[] a = fa.apply(size);
 822         long[] b = fb.apply(size);
 823         boolean[] ms = fm.apply(size);
 824         VectorMask<Long> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 825 
 826         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 827             for (int i = 0; i < a.length; i += SPECIES.length()) {
 828                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 829                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 830                 VectorMask<Long> mv = av.notEqual(bv);
 831 
 832                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 833             }
 834         }
 835         return m;
 836     }
 837 
 838 
 839     @Benchmark
 840     public Object lessThanEq() {
 841         long[] a = fa.apply(size);
 842         long[] b = fb.apply(size);
 843         boolean[] ms = fm.apply(size);
 844         VectorMask<Long> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 845 
 846         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 847             for (int i = 0; i < a.length; i += SPECIES.length()) {
 848                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 849                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 850                 VectorMask<Long> mv = av.lessThanEq(bv);
 851 
 852                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 853             }
 854         }
 855         return m;
 856     }
 857 
 858 
 859     @Benchmark
 860     public Object greaterThanEq() {
 861         long[] a = fa.apply(size);
 862         long[] b = fb.apply(size);
 863         boolean[] ms = fm.apply(size);
 864         VectorMask<Long> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 865 
 866         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 867             for (int i = 0; i < a.length; i += SPECIES.length()) {
 868                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 869                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 870                 VectorMask<Long> mv = av.greaterThanEq(bv);
 871 
 872                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 873             }
 874         }
 875         return m;
 876     }
 877 
 878 
 879     @Benchmark
 880     public void blend(Blackhole bh) {
 881         long[] a = fa.apply(SPECIES.length());
 882         long[] b = fb.apply(SPECIES.length());
 883         long[] r = fr.apply(SPECIES.length());
 884         boolean[] mask = fm.apply(SPECIES.length());
 885         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
 886 
 887         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 888             for (int i = 0; i < a.length; i += SPECIES.length()) {
 889                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 890                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 891                 av.blend(bv, vmask).intoArray(r, i);
 892             }
 893         }
 894 
 895         bh.consume(r);
 896     }
 897 
 898     @Benchmark
 899     public void rearrange(Blackhole bh) {
 900         long[] a = fa.apply(SPECIES.length());
 901         int[] order = fs.apply(a.length, SPECIES.length());
 902         long[] r = fr.apply(SPECIES.length());
 903 
 904         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 905             for (int i = 0; i < a.length; i += SPECIES.length()) {
 906                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 907                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
 908             }
 909         }
 910 
 911         bh.consume(r);
 912     }
 913 
 914     @Benchmark
 915     public void extract(Blackhole bh) {
 916         long[] a = fa.apply(SPECIES.length());
 917         long[] r = fr.apply(SPECIES.length());
 918 
 919         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 920             for (int i = 0; i < a.length; i += SPECIES.length()) {
 921                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 922                 int num_lanes = SPECIES.length();
 923                 // Manually unroll because full unroll happens after intrinsification.
 924                 // Unroll is needed because get intrinsic requires for index to be a known constant.
 925                 if (num_lanes == 1) {
 926                     r[i]=av.get(0);
 927                 } else if (num_lanes == 2) {


1090     @Benchmark
1091     public void neg(Blackhole bh) {
1092         long[] a = fa.apply(SPECIES.length());
1093         long[] r = fr.apply(SPECIES.length());
1094 
1095         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1096             for (int i = 0; i < a.length; i += SPECIES.length()) {
1097                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1098                 av.neg().intoArray(r, i);
1099             }
1100         }
1101 
1102         bh.consume(r);
1103     }
1104 
1105     @Benchmark
1106     public void negMasked(Blackhole bh) {
1107         long[] a = fa.apply(SPECIES.length());
1108         long[] r = fr.apply(SPECIES.length());
1109         boolean[] mask = fm.apply(SPECIES.length());
1110         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
1111 
1112         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1113             for (int i = 0; i < a.length; i += SPECIES.length()) {
1114                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1115                 av.neg(vmask).intoArray(r, i);
1116             }
1117         }
1118 
1119         bh.consume(r);
1120     }
1121 
1122     @Benchmark
1123     public void abs(Blackhole bh) {
1124         long[] a = fa.apply(SPECIES.length());
1125         long[] r = fr.apply(SPECIES.length());
1126 
1127         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1128             for (int i = 0; i < a.length; i += SPECIES.length()) {
1129                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1130                 av.abs().intoArray(r, i);
1131             }
1132         }
1133 
1134         bh.consume(r);
1135     }
1136 
1137     @Benchmark
1138     public void absMasked(Blackhole bh) {
1139         long[] a = fa.apply(SPECIES.length());
1140         long[] r = fr.apply(SPECIES.length());
1141         boolean[] mask = fm.apply(SPECIES.length());
1142         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
1143 
1144         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1145             for (int i = 0; i < a.length; i += SPECIES.length()) {
1146                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1147                 av.abs(vmask).intoArray(r, i);
1148             }
1149         }
1150 
1151         bh.consume(r);
1152     }
1153 
1154 
1155     @Benchmark
1156     public void not(Blackhole bh) {
1157         long[] a = fa.apply(SPECIES.length());
1158         long[] r = fr.apply(SPECIES.length());
1159 
1160         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1161             for (int i = 0; i < a.length; i += SPECIES.length()) {
1162                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1163                 av.not().intoArray(r, i);
1164             }
1165         }
1166 
1167         bh.consume(r);
1168     }
1169 
1170 
1171 
1172     @Benchmark
1173     public void notMasked(Blackhole bh) {
1174         long[] a = fa.apply(SPECIES.length());
1175         long[] r = fr.apply(SPECIES.length());
1176         boolean[] mask = fm.apply(SPECIES.length());
1177         VectorMask<Long> vmask = VectorMask.fromValues(SPECIES, mask);
1178 
1179         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1180             for (int i = 0; i < a.length; i += SPECIES.length()) {
1181                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1182                 av.not(vmask).intoArray(r, i);
1183             }
1184         }
1185 
1186         bh.consume(r);
1187     }
1188 
1189 
1190 
1191 
1192 
1193     @Benchmark
1194     public void gather(Blackhole bh) {
1195         long[] a = fa.apply(SPECIES.length());
1196         int[] b    = fs.apply(a.length, SPECIES.length());
1197         long[] r = new long[a.length];


< prev index next >