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.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 LongMaxVector extends AbstractVectorBenchmark {
  46     static final VectorSpecies<Long> SPECIES = LongVector.SPECIES_MAX;
  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() {
  67         size += size % SPECIES.length(); // FIXME: add post-loops
  68 
  69         a = fill(i -> (long)(2*i));
  70         b = fill(i -> (long)(i+1));
  71         c = fill(i -> (long)(i+5));
  72         r = fill(i -> (long)0);
  73 
  74         m = fillMask(size, i -> (i % 2) == 0);
  75         rm = fillMask(size, i -> false);
  76 
  77         s = fillInt(size, i -> RANDOM.nextInt(SPECIES.length()));
  78     }
  79 
  80     final IntFunction<long[]> fa = vl -> a;
  81     final IntFunction<long[]> fb = vl -> b;
  82     final IntFunction<long[]> fc = vl -> c;
  83     final IntFunction<long[]> fr = vl -> r;
  84     final IntFunction<boolean[]> fm = vl -> m;
  85     final IntFunction<boolean[]> fmr = vl -> rm;
  86     final BiFunction<Integer,Integer,int[]> fs = (i,j) -> s;
  87 
  88 
  89     @Benchmark
  90     public void add(Blackhole bh) {
  91         long[] a = fa.apply(SPECIES.length());
  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 
 561 
 562 
 563 
 564 
 565     @Benchmark
 566     public void max(Blackhole bh) {
 567         long[] a = fa.apply(SPECIES.length());
 568         long[] b = fb.apply(SPECIES.length());
 569         long[] r = fr.apply(SPECIES.length());
 570 
 571         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 572             for (int i = 0; i < a.length; i += SPECIES.length()) {
 573                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 574                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 575                 av.max(bv).intoArray(r, i);
 576             }
 577         }
 578 
 579         bh.consume(r);
 580     }
 581 
 582     @Benchmark
 583     public void min(Blackhole bh) {
 584         long[] a = fa.apply(SPECIES.length());
 585         long[] b = fb.apply(SPECIES.length());
 586         long[] r = fr.apply(SPECIES.length());
 587 
 588         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 589             for (int i = 0; i < a.length; i += SPECIES.length()) {
 590                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 591                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
 592                 av.min(bv).intoArray(r, i);
 593             }
 594         }
 595 
 596         bh.consume(r);
 597     }
 598 
 599 
 600     @Benchmark
 601     public void andAll(Blackhole bh) {
 602         long[] a = fa.apply(SPECIES.length());
 603         long ra = -1;
 604 
 605         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 606             ra = -1;
 607             for (int i = 0; i < a.length; i += SPECIES.length()) {
 608                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 609                 ra &= av.andAll();
 610             }
 611         }
 612         bh.consume(ra);
 613     }
 614 
 615 
 616 
 617     @Benchmark
 618     public void orAll(Blackhole bh) {
 619         long[] a = fa.apply(SPECIES.length());
 620         long ra = 0;
 621 
 622         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 623             ra = 0;
 624             for (int i = 0; i < a.length; i += SPECIES.length()) {
 625                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 626                 ra |= av.orAll();
 627             }
 628         }
 629         bh.consume(ra);
 630     }
 631 
 632 
 633 
 634     @Benchmark
 635     public void xorAll(Blackhole bh) {
 636         long[] a = fa.apply(SPECIES.length());
 637         long ra = 0;
 638 
 639         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 640             ra = 0;
 641             for (int i = 0; i < a.length; i += SPECIES.length()) {
 642                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 643                 ra ^= av.xorAll();
 644             }
 645         }
 646         bh.consume(ra);
 647     }
 648 
 649 
 650     @Benchmark
 651     public void addAll(Blackhole bh) {
 652         long[] a = fa.apply(SPECIES.length());
 653         long ra = 0;
 654 
 655         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 656             ra = 0;
 657             for (int i = 0; i < a.length; i += SPECIES.length()) {
 658                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 659                 ra += av.addAll();
 660             }
 661         }
 662         bh.consume(ra);
 663     }
 664 
 665     @Benchmark
 666     public void mulAll(Blackhole bh) {
 667         long[] a = fa.apply(SPECIES.length());
 668         long ra = 1;
 669 
 670         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 671             ra = 1;
 672             for (int i = 0; i < a.length; i += SPECIES.length()) {
 673                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 674                 ra *= av.mulAll();
 675             }
 676         }
 677         bh.consume(ra);
 678     }
 679 
 680     @Benchmark
 681     public void minAll(Blackhole bh) {
 682         long[] a = fa.apply(SPECIES.length());
 683         long ra = Long.MAX_VALUE;
 684 
 685         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 686             ra = Long.MAX_VALUE;
 687             for (int i = 0; i < a.length; i += SPECIES.length()) {
 688                 LongVector av = LongVector.fromArray(SPECIES, a, i);
 689                 ra = (long)Math.min(ra, av.minAll());
 690             }
 691         }
 692         bh.consume(ra);
 693     }
 694 
 695     @Benchmark
 696     public void maxAll(Blackhole bh) {
 697         long[] a = fa.apply(SPECIES.length());
 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) {
 928                     r[i]=av.get(0);
 929                     r[i+1]=av.get(1);
 930                 } else if (num_lanes == 4) {
 931                     r[i]=av.get(0);
 932                     r[i+1]=av.get(1);
 933                     r[i+2]=av.get(2);
 934                     r[i+3]=av.get(3);
 935                 } else if (num_lanes == 8) {
 936                     r[i]=av.get(0);
 937                     r[i+1]=av.get(1);
 938                     r[i+2]=av.get(2);
 939                     r[i+3]=av.get(3);
 940                     r[i+4]=av.get(4);
 941                     r[i+5]=av.get(5);
 942                     r[i+6]=av.get(6);
 943                     r[i+7]=av.get(7);
 944                 } else if (num_lanes == 16) {
 945                     r[i]=av.get(0);
 946                     r[i+1]=av.get(1);
 947                     r[i+2]=av.get(2);
 948                     r[i+3]=av.get(3);
 949                     r[i+4]=av.get(4);
 950                     r[i+5]=av.get(5);
 951                     r[i+6]=av.get(6);
 952                     r[i+7]=av.get(7);
 953                     r[i+8]=av.get(8);
 954                     r[i+9]=av.get(9);
 955                     r[i+10]=av.get(10);
 956                     r[i+11]=av.get(11);
 957                     r[i+12]=av.get(12);
 958                     r[i+13]=av.get(13);
 959                     r[i+14]=av.get(14);
 960                     r[i+15]=av.get(15);
 961                 } else if (num_lanes == 32) {
 962                     r[i]=av.get(0);
 963                     r[i+1]=av.get(1);
 964                     r[i+2]=av.get(2);
 965                     r[i+3]=av.get(3);
 966                     r[i+4]=av.get(4);
 967                     r[i+5]=av.get(5);
 968                     r[i+6]=av.get(6);
 969                     r[i+7]=av.get(7);
 970                     r[i+8]=av.get(8);
 971                     r[i+9]=av.get(9);
 972                     r[i+10]=av.get(10);
 973                     r[i+11]=av.get(11);
 974                     r[i+12]=av.get(12);
 975                     r[i+13]=av.get(13);
 976                     r[i+14]=av.get(14);
 977                     r[i+15]=av.get(15);
 978                     r[i+16]=av.get(16);
 979                     r[i+17]=av.get(17);
 980                     r[i+18]=av.get(18);
 981                     r[i+19]=av.get(19);
 982                     r[i+20]=av.get(20);
 983                     r[i+21]=av.get(21);
 984                     r[i+22]=av.get(22);
 985                     r[i+23]=av.get(23);
 986                     r[i+24]=av.get(24);
 987                     r[i+25]=av.get(25);
 988                     r[i+26]=av.get(26);
 989                     r[i+27]=av.get(27);
 990                     r[i+28]=av.get(28);
 991                     r[i+29]=av.get(29);
 992                     r[i+30]=av.get(30);
 993                     r[i+31]=av.get(31);
 994                 } else if (num_lanes == 64) {
 995                     r[i]=av.get(0);
 996                     r[i+1]=av.get(1);
 997                     r[i+2]=av.get(2);
 998                     r[i+3]=av.get(3);
 999                     r[i+4]=av.get(4);
1000                     r[i+5]=av.get(5);
1001                     r[i+6]=av.get(6);
1002                     r[i+7]=av.get(7);
1003                     r[i+8]=av.get(8);
1004                     r[i+9]=av.get(9);
1005                     r[i+10]=av.get(10);
1006                     r[i+11]=av.get(11);
1007                     r[i+12]=av.get(12);
1008                     r[i+13]=av.get(13);
1009                     r[i+14]=av.get(14);
1010                     r[i+15]=av.get(15);
1011                     r[i+16]=av.get(16);
1012                     r[i+17]=av.get(17);
1013                     r[i+18]=av.get(18);
1014                     r[i+19]=av.get(19);
1015                     r[i+20]=av.get(20);
1016                     r[i+21]=av.get(21);
1017                     r[i+22]=av.get(22);
1018                     r[i+23]=av.get(23);
1019                     r[i+24]=av.get(24);
1020                     r[i+25]=av.get(25);
1021                     r[i+26]=av.get(26);
1022                     r[i+27]=av.get(27);
1023                     r[i+28]=av.get(28);
1024                     r[i+29]=av.get(29);
1025                     r[i+30]=av.get(30);
1026                     r[i+31]=av.get(31);
1027                     r[i+32]=av.get(32);
1028                     r[i+33]=av.get(33);
1029                     r[i+34]=av.get(34);
1030                     r[i+35]=av.get(35);
1031                     r[i+36]=av.get(36);
1032                     r[i+37]=av.get(37);
1033                     r[i+38]=av.get(38);
1034                     r[i+39]=av.get(39);
1035                     r[i+40]=av.get(40);
1036                     r[i+41]=av.get(41);
1037                     r[i+42]=av.get(42);
1038                     r[i+43]=av.get(43);
1039                     r[i+44]=av.get(44);
1040                     r[i+45]=av.get(45);
1041                     r[i+46]=av.get(46);
1042                     r[i+47]=av.get(47);
1043                     r[i+48]=av.get(48);
1044                     r[i+49]=av.get(49);
1045                     r[i+50]=av.get(50);
1046                     r[i+51]=av.get(51);
1047                     r[i+52]=av.get(52);
1048                     r[i+53]=av.get(53);
1049                     r[i+54]=av.get(54);
1050                     r[i+55]=av.get(55);
1051                     r[i+56]=av.get(56);
1052                     r[i+57]=av.get(57);
1053                     r[i+58]=av.get(58);
1054                     r[i+59]=av.get(59);
1055                     r[i+60]=av.get(60);
1056                     r[i+61]=av.get(61);
1057                     r[i+62]=av.get(62);
1058                     r[i+63]=av.get(63);
1059                 } else {
1060                     for (int j = 0; j < SPECIES.length(); j++) {
1061                         r[i+j]=av.get(j);
1062                     }
1063                 }
1064             }
1065         }
1066 
1067         bh.consume(r);
1068     }
1069 
1070 
1071 
1072 
1073 
1074 
1075 
1076 
1077 
1078 
1079 
1080 
1081 
1082 
1083 
1084 
1085 
1086 
1087 
1088 
1089 
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];
1198 
1199         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1200             for (int i = 0; i < a.length; i += SPECIES.length()) {
1201                 LongVector av = LongVector.fromArray(SPECIES, a, i, b, i);
1202                 av.intoArray(r, i);
1203             }
1204         }
1205 
1206         bh.consume(r);
1207     }
1208 
1209 
1210 
1211     @Benchmark
1212     public void scatter(Blackhole bh) {
1213         long[] a = fa.apply(SPECIES.length());
1214         int[] b = fs.apply(a.length, SPECIES.length());
1215         long[] r = new long[a.length];
1216 
1217         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1218             for (int i = 0; i < a.length; i += SPECIES.length()) {
1219                 LongVector av = LongVector.fromArray(SPECIES, a, i);
1220                 av.intoArray(r, i, b, i);
1221             }
1222         }
1223 
1224         bh.consume(r);
1225     }
1226 
1227 }
1228 
--- EOF ---