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

   1 /*
   2  * Copyright (c) 2018, 2019, 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.
   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.IntVector;
  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 Int128Vector extends AbstractVectorBenchmark {
  45     static final Species<Integer> SPECIES = IntVector.SPECIES_128;
  46 
  47     static final int INVOC_COUNT = 1; // get rid of outer loop
  48 
  49     @Param("1024")
  50     int size;
  51 
  52     int[] fill(IntFunction<Integer> f) {
  53         int[] array = new int[size];
  54         for (int i = 0; i < array.length; i++) {
  55             array[i] = f.apply(i);
  56         }
  57         return array;
  58     }
  59 
  60     int[] a, b, c, r;
  61     boolean[] m, rm;
  62     int[] s;
  63 
  64     @Setup
  65     public void init() {
  66         size += size % SPECIES.length(); // FIXME: add post-loops
  67 
  68         a = fill(i -> (int)(2*i));
  69         b = fill(i -> (int)(i+1));
  70         c = fill(i -> (int)(i+5));
  71         r = fill(i -> (int)0);
  72 
  73         m = fillMask(size, i -> (i % 2) == 0);
  74         rm = fillMask(size, i -> false);
  75 
  76         s = fillInt(size, i -> RANDOM.nextInt(SPECIES.length()));
  77     }
  78 
  79     final IntFunction<int[]> fa = vl -> a;
  80     final IntFunction<int[]> fb = vl -> b;
  81     final IntFunction<int[]> fc = vl -> c;
  82     final IntFunction<int[]> fr = vl -> r;
  83     final IntFunction<boolean[]> fm = vl -> m;
  84     final IntFunction<boolean[]> fmr = vl -> rm;
  85     final BiFunction<Integer,Integer,int[]> fs = (i,j) -> s;
  86 
  87 
  88     @Benchmark
  89     public void add(Blackhole bh) {
  90         int[] a = fa.apply(SPECIES.length());
  91         int[] b = fb.apply(SPECIES.length());
  92         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
  97                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 108         int[] b = fb.apply(SPECIES.length());
 109         int[] r = fr.apply(SPECIES.length());
 110         boolean[] mask = fm.apply(SPECIES.length());
 111         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 116                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 127         int[] b = fb.apply(SPECIES.length());
 128         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 133                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 144         int[] b = fb.apply(SPECIES.length());
 145         int[] r = fr.apply(SPECIES.length());
 146         boolean[] mask = fm.apply(SPECIES.length());
 147         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 152                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 165         int[] b = fb.apply(SPECIES.length());
 166         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 171                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 182         int[] b = fb.apply(SPECIES.length());
 183         int[] r = fr.apply(SPECIES.length());
 184         boolean[] mask = fm.apply(SPECIES.length());
 185         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 190                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 202         int[] b = fb.apply(SPECIES.length());
 203         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 208                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 221         int[] b = fb.apply(SPECIES.length());
 222         int[] r = fr.apply(SPECIES.length());
 223         boolean[] mask = fm.apply(SPECIES.length());
 224         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 229                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 242         int[] b = fb.apply(SPECIES.length());
 243         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 248                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 261         int[] b = fb.apply(SPECIES.length());
 262         int[] r = fr.apply(SPECIES.length());
 263         boolean[] mask = fm.apply(SPECIES.length());
 264         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 269                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 282         int[] b = fb.apply(SPECIES.length());
 283         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 288                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 301         int[] b = fb.apply(SPECIES.length());
 302         int[] r = fr.apply(SPECIES.length());
 303         boolean[] mask = fm.apply(SPECIES.length());
 304         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 309                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 322         int[] b = fb.apply(SPECIES.length());
 323         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 328                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 341         int[] b = fb.apply(SPECIES.length());
 342         int[] r = fr.apply(SPECIES.length());
 343         boolean[] mask = fm.apply(SPECIES.length());
 344         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 349                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 362         int[] b = fb.apply(SPECIES.length());
 363         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 368                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 381         int[] b = fb.apply(SPECIES.length());
 382         int[] r = fr.apply(SPECIES.length());
 383         boolean[] mask = fm.apply(SPECIES.length());
 384         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 389                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 402         int[] b = fb.apply(SPECIES.length());
 403         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 408                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 421         int[] b = fb.apply(SPECIES.length());
 422         int[] r = fr.apply(SPECIES.length());
 423         boolean[] mask = fm.apply(SPECIES.length());
 424         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 429                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 442         int[] b = fb.apply(SPECIES.length());
 443         int[] 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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
 460         int[] b = fb.apply(SPECIES.length());
 461         int[] r = fr.apply(SPECIES.length());
 462         boolean[] mask = fm.apply(SPECIES.length());
 463         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
 480         int[] b = fb.apply(SPECIES.length());
 481         int[] 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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
 498         int[] b = fb.apply(SPECIES.length());
 499         int[] r = fr.apply(SPECIES.length());
 500         boolean[] mask = fm.apply(SPECIES.length());
 501         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
 518         int[] b = fb.apply(SPECIES.length());
 519         int[] 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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
 536         int[] b = fb.apply(SPECIES.length());
 537         int[] r = fr.apply(SPECIES.length());
 538         boolean[] mask = fm.apply(SPECIES.length());
 539         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.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 
 560 
 561 
 562 
 563 
 564     @Benchmark
 565     public void max(Blackhole bh) {
 566         int[] a = fa.apply(SPECIES.length());
 567         int[] b = fb.apply(SPECIES.length());
 568         int[] r = fr.apply(SPECIES.length());
 569 
 570         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 571             for (int i = 0; i < a.length; i += SPECIES.length()) {
 572                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 573                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 574                 av.max(bv).intoArray(r, i);
 575             }
 576         }
 577 
 578         bh.consume(r);
 579     }
 580 
 581     @Benchmark
 582     public void min(Blackhole bh) {
 583         int[] a = fa.apply(SPECIES.length());
 584         int[] b = fb.apply(SPECIES.length());
 585         int[] r = fr.apply(SPECIES.length());
 586 
 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 590                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 591                 av.min(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         bh.consume(r);
 596     }
 597 
 598 
 599     @Benchmark
 600     public void andAll(Blackhole bh) {
 601         int[] a = fa.apply(SPECIES.length());
 602         int ra = -1;
 603 
 604         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 605             ra = -1;
 606             for (int i = 0; i < a.length; i += SPECIES.length()) {
 607                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 608                 ra &= av.andAll();
 609             }
 610         }
 611         bh.consume(ra);
 612     }
 613 
 614 
 615 
 616     @Benchmark
 617     public void orAll(Blackhole bh) {
 618         int[] a = fa.apply(SPECIES.length());
 619         int ra = 0;
 620 
 621         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 622             ra = 0;
 623             for (int i = 0; i < a.length; i += SPECIES.length()) {
 624                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 625                 ra |= av.orAll();
 626             }
 627         }
 628         bh.consume(ra);
 629     }
 630 
 631 
 632 
 633     @Benchmark
 634     public void xorAll(Blackhole bh) {
 635         int[] a = fa.apply(SPECIES.length());
 636         int ra = 0;
 637 
 638         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 639             ra = 0;
 640             for (int i = 0; i < a.length; i += SPECIES.length()) {
 641                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 642                 ra ^= av.xorAll();
 643             }
 644         }
 645         bh.consume(ra);
 646     }
 647 
 648 
 649     @Benchmark
 650     public void addAll(Blackhole bh) {
 651         int[] a = fa.apply(SPECIES.length());
 652         int ra = 0;
 653 
 654         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 655             ra = 0;
 656             for (int i = 0; i < a.length; i += SPECIES.length()) {
 657                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 658                 ra += av.addAll();
 659             }
 660         }
 661         bh.consume(ra);
 662     }
 663 
 664     @Benchmark
 665     public void mulAll(Blackhole bh) {
 666         int[] a = fa.apply(SPECIES.length());
 667         int ra = 1;
 668 
 669         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 670             ra = 1;
 671             for (int i = 0; i < a.length; i += SPECIES.length()) {
 672                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 673                 ra *= av.mulAll();
 674             }
 675         }
 676         bh.consume(ra);
 677     }
 678 
 679     @Benchmark
 680     public void minAll(Blackhole bh) {
 681         int[] a = fa.apply(SPECIES.length());
 682         int ra = Integer.MAX_VALUE;
 683 
 684         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 685             ra = Integer.MAX_VALUE;
 686             for (int i = 0; i < a.length; i += SPECIES.length()) {
 687                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 688                 ra = (int)Math.min(ra, av.minAll());
 689             }
 690         }
 691         bh.consume(ra);
 692     }
 693 
 694     @Benchmark
 695     public void maxAll(Blackhole bh) {
 696         int[] a = fa.apply(SPECIES.length());
 697         int ra = Integer.MIN_VALUE;
 698 
 699         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 700             ra = Integer.MIN_VALUE;
 701             for (int i = 0; i < a.length; i += SPECIES.length()) {
 702                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 703                 ra = (int)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<Integer> vmask = IntVector.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<Integer> vmask = IntVector.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         int[] a = fa.apply(SPECIES.length());
 746         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 751                 av.with(0, (int)4).intoArray(r, i);
 752             }
 753         }
 754 
 755         bh.consume(r);
 756     }
 757 
 758     @Benchmark
 759     public Object lessThan() {
 760         int[] a = fa.apply(size);
 761         int[] b = fb.apply(size);
 762         boolean[] ms = fm.apply(size);
 763         Vector.Mask<Integer> m = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 768                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 769                 Vector.Mask<Integer> 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         int[] a = fa.apply(size);
 781         int[] b = fb.apply(size);
 782         boolean[] ms = fm.apply(size);
 783         Vector.Mask<Integer> m = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 788                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 789                 Vector.Mask<Integer> 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         int[] a = fa.apply(size);
 801         int[] b = fb.apply(size);
 802         boolean[] ms = fm.apply(size);
 803         Vector.Mask<Integer> m = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 808                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 809                 Vector.Mask<Integer> 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         int[] a = fa.apply(size);
 821         int[] b = fb.apply(size);
 822         boolean[] ms = fm.apply(size);
 823         Vector.Mask<Integer> m = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 828                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 829                 Vector.Mask<Integer> 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         int[] a = fa.apply(size);
 841         int[] b = fb.apply(size);
 842         boolean[] ms = fm.apply(size);
 843         Vector.Mask<Integer> m = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 848                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 849                 Vector.Mask<Integer> 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         int[] a = fa.apply(size);
 861         int[] b = fb.apply(size);
 862         boolean[] ms = fm.apply(size);
 863         Vector.Mask<Integer> m = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 868                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 869                 Vector.Mask<Integer> 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         int[] a = fa.apply(SPECIES.length());
 881         int[] b = fb.apply(SPECIES.length());
 882         int[] r = fr.apply(SPECIES.length());
 883         boolean[] mask = fm.apply(SPECIES.length());
 884         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 889                 IntVector bv = IntVector.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         int[] a = fa.apply(SPECIES.length());
 900         int[] order = fs.apply(a.length, SPECIES.length());
 901         int[] 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 906                 av.rearrange(IntVector.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         int[] a = fa.apply(SPECIES.length());
 916         int[] 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                 IntVector av = IntVector.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) {
 927                     r[i]=av.get(0);
 928                     r[i+1]=av.get(1);
 929                 } else if (num_lanes == 4) {
 930                     r[i]=av.get(0);
 931                     r[i+1]=av.get(1);
 932                     r[i+2]=av.get(2);
 933                     r[i+3]=av.get(3);
 934                 } else if (num_lanes == 8) {
 935                     r[i]=av.get(0);
 936                     r[i+1]=av.get(1);
 937                     r[i+2]=av.get(2);
 938                     r[i+3]=av.get(3);
 939                     r[i+4]=av.get(4);
 940                     r[i+5]=av.get(5);
 941                     r[i+6]=av.get(6);
 942                     r[i+7]=av.get(7);
 943                 } else if (num_lanes == 16) {
 944                     r[i]=av.get(0);
 945                     r[i+1]=av.get(1);
 946                     r[i+2]=av.get(2);
 947                     r[i+3]=av.get(3);
 948                     r[i+4]=av.get(4);
 949                     r[i+5]=av.get(5);
 950                     r[i+6]=av.get(6);
 951                     r[i+7]=av.get(7);
 952                     r[i+8]=av.get(8);
 953                     r[i+9]=av.get(9);
 954                     r[i+10]=av.get(10);
 955                     r[i+11]=av.get(11);
 956                     r[i+12]=av.get(12);
 957                     r[i+13]=av.get(13);
 958                     r[i+14]=av.get(14);
 959                     r[i+15]=av.get(15);
 960                 } else if (num_lanes == 32) {
 961                     r[i]=av.get(0);
 962                     r[i+1]=av.get(1);
 963                     r[i+2]=av.get(2);
 964                     r[i+3]=av.get(3);
 965                     r[i+4]=av.get(4);
 966                     r[i+5]=av.get(5);
 967                     r[i+6]=av.get(6);
 968                     r[i+7]=av.get(7);
 969                     r[i+8]=av.get(8);
 970                     r[i+9]=av.get(9);
 971                     r[i+10]=av.get(10);
 972                     r[i+11]=av.get(11);
 973                     r[i+12]=av.get(12);
 974                     r[i+13]=av.get(13);
 975                     r[i+14]=av.get(14);
 976                     r[i+15]=av.get(15);
 977                     r[i+16]=av.get(16);
 978                     r[i+17]=av.get(17);
 979                     r[i+18]=av.get(18);
 980                     r[i+19]=av.get(19);
 981                     r[i+20]=av.get(20);
 982                     r[i+21]=av.get(21);
 983                     r[i+22]=av.get(22);
 984                     r[i+23]=av.get(23);
 985                     r[i+24]=av.get(24);
 986                     r[i+25]=av.get(25);
 987                     r[i+26]=av.get(26);
 988                     r[i+27]=av.get(27);
 989                     r[i+28]=av.get(28);
 990                     r[i+29]=av.get(29);
 991                     r[i+30]=av.get(30);
 992                     r[i+31]=av.get(31);
 993                 } else if (num_lanes == 64) {
 994                     r[i]=av.get(0);
 995                     r[i+1]=av.get(1);
 996                     r[i+2]=av.get(2);
 997                     r[i+3]=av.get(3);
 998                     r[i+4]=av.get(4);
 999                     r[i+5]=av.get(5);
1000                     r[i+6]=av.get(6);
1001                     r[i+7]=av.get(7);
1002                     r[i+8]=av.get(8);
1003                     r[i+9]=av.get(9);
1004                     r[i+10]=av.get(10);
1005                     r[i+11]=av.get(11);
1006                     r[i+12]=av.get(12);
1007                     r[i+13]=av.get(13);
1008                     r[i+14]=av.get(14);
1009                     r[i+15]=av.get(15);
1010                     r[i+16]=av.get(16);
1011                     r[i+17]=av.get(17);
1012                     r[i+18]=av.get(18);
1013                     r[i+19]=av.get(19);
1014                     r[i+20]=av.get(20);
1015                     r[i+21]=av.get(21);
1016                     r[i+22]=av.get(22);
1017                     r[i+23]=av.get(23);
1018                     r[i+24]=av.get(24);
1019                     r[i+25]=av.get(25);
1020                     r[i+26]=av.get(26);
1021                     r[i+27]=av.get(27);
1022                     r[i+28]=av.get(28);
1023                     r[i+29]=av.get(29);
1024                     r[i+30]=av.get(30);
1025                     r[i+31]=av.get(31);
1026                     r[i+32]=av.get(32);
1027                     r[i+33]=av.get(33);
1028                     r[i+34]=av.get(34);
1029                     r[i+35]=av.get(35);
1030                     r[i+36]=av.get(36);
1031                     r[i+37]=av.get(37);
1032                     r[i+38]=av.get(38);
1033                     r[i+39]=av.get(39);
1034                     r[i+40]=av.get(40);
1035                     r[i+41]=av.get(41);
1036                     r[i+42]=av.get(42);
1037                     r[i+43]=av.get(43);
1038                     r[i+44]=av.get(44);
1039                     r[i+45]=av.get(45);
1040                     r[i+46]=av.get(46);
1041                     r[i+47]=av.get(47);
1042                     r[i+48]=av.get(48);
1043                     r[i+49]=av.get(49);
1044                     r[i+50]=av.get(50);
1045                     r[i+51]=av.get(51);
1046                     r[i+52]=av.get(52);
1047                     r[i+53]=av.get(53);
1048                     r[i+54]=av.get(54);
1049                     r[i+55]=av.get(55);
1050                     r[i+56]=av.get(56);
1051                     r[i+57]=av.get(57);
1052                     r[i+58]=av.get(58);
1053                     r[i+59]=av.get(59);
1054                     r[i+60]=av.get(60);
1055                     r[i+61]=av.get(61);
1056                     r[i+62]=av.get(62);
1057                     r[i+63]=av.get(63);
1058                 } else {
1059                     for (int j = 0; j < SPECIES.length(); j++) {
1060                         r[i+j]=av.get(j);
1061                     }
1062                 }
1063             }
1064         }
1065 
1066         bh.consume(r);
1067     }
1068 
1069 
1070 
1071 
1072 
1073 
1074 
1075 
1076 
1077 
1078 
1079 
1080 
1081 
1082 
1083 
1084 
1085 
1086 
1087 
1088 
1089     @Benchmark
1090     public void neg(Blackhole bh) {
1091         int[] a = fa.apply(SPECIES.length());
1092         int[] 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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
1107         int[] r = fr.apply(SPECIES.length());
1108         boolean[] mask = fm.apply(SPECIES.length());
1109         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
1124         int[] 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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
1139         int[] r = fr.apply(SPECIES.length());
1140         boolean[] mask = fm.apply(SPECIES.length());
1141         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
1157         int[] 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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
1174         int[] r = fr.apply(SPECIES.length());
1175         boolean[] mask = fm.apply(SPECIES.length());
1176         Vector.Mask<Integer> vmask = IntVector.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                 IntVector av = IntVector.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         int[] a = fa.apply(SPECIES.length());
1195         int[] b    = fs.apply(a.length, SPECIES.length());
1196         int[] r = new int[a.length];
1197 
1198         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1199             for (int i = 0; i < a.length; i += SPECIES.length()) {
1200                 IntVector av = IntVector.fromArray(SPECIES, a, i, b, i);
1201                 av.intoArray(r, i);
1202             }
1203         }
1204 
1205         bh.consume(r);
1206     }
1207 
1208 
1209 
1210     @Benchmark
1211     public void scatter(Blackhole bh) {
1212         int[] a = fa.apply(SPECIES.length());
1213         int[] b = fs.apply(a.length, SPECIES.length());
1214         int[] r = new int[a.length];
1215 
1216         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1217             for (int i = 0; i < a.length; i += SPECIES.length()) {
1218                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1219                 av.intoArray(r, i, b, i);
1220             }
1221         }
1222 
1223         bh.consume(r);
1224     }
1225 
1226 }
1227 
--- EOF ---