1 /*
   2  * Copyright (c) 2018, 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 java.util.concurrent.TimeUnit;
  27 import java.util.function.IntFunction;
  28 
  29 import org.openjdk.jmh.annotations.*;
  30 
  31 @BenchmarkMode(Mode.Throughput)
  32 @OutputTimeUnit(TimeUnit.MILLISECONDS)
  33 @State(Scope.Benchmark)
  34 @Warmup(iterations = 3, time = 1)
  35 @Measurement(iterations = 5, time = 1)
  36 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
  37 public class IntScalar extends AbstractVectorBenchmark {
  38     @Param("1024")
  39     int size;
  40 
  41     int[] fill(IntFunction<Integer> f) {
  42         int[] array = new int[size];
  43         for (int i = 0; i < array.length; i++) {
  44             array[i] = f.apply(i);
  45         }
  46         return array;
  47     }
  48 
  49     int[] as, bs, cs, rs;
  50     boolean[] ms, rms;
  51     int[] ss;
  52 
  53     @Setup
  54     public void init() {
  55         as = fill(i -> (int)(2*i));
  56         bs = fill(i -> (int)(i+1));
  57         cs = fill(i -> (int)(i+5));
  58         rs = fill(i -> (int)0);
  59         ms = fillMask(size, i -> (i % 2) == 0);
  60         rms = fillMask(size, i -> false);
  61 
  62         ss = fillInt(size, i -> RANDOM.nextInt(Math.max(i,1)));
  63     }
  64 
  65     final IntFunction<int[]> fa = vl -> as;
  66     final IntFunction<int[]> fb = vl -> bs;
  67     final IntFunction<int[]> fc = vl -> cs;
  68     final IntFunction<int[]> fr = vl -> rs;
  69     final IntFunction<boolean[]> fm = vl -> ms;
  70     final IntFunction<boolean[]> fmr = vl -> rms;
  71     final IntFunction<int[]> fs = vl -> ss;
  72 
  73 
  74     @Benchmark
  75     public Object add() {
  76         int[] as = fa.apply(size);
  77         int[] bs = fb.apply(size);
  78         int[] rs = fr.apply(size);
  79 
  80         for (int i = 0; i < as.length; i++) {
  81             int a = as[i];
  82             int b = bs[i];
  83             rs[i] = (int)(a + b);
  84         }
  85 
  86         return rs;
  87     }
  88 
  89     @Benchmark
  90     public Object addMasked() {
  91         int[] as = fa.apply(size);
  92         int[] bs = fb.apply(size);
  93         int[] rs = fr.apply(size);
  94         boolean[] ms = fm.apply(size);
  95 
  96         for (int i = 0; i < as.length; i++) {
  97             int a = as[i];
  98             int b = bs[i];
  99             if (ms[i % ms.length]) {
 100                 rs[i] = (int)(a + b);
 101             } else {
 102                 rs[i] = a;
 103             }
 104         }
 105         return rs;
 106     }
 107 
 108     @Benchmark
 109     public Object sub() {
 110         int[] as = fa.apply(size);
 111         int[] bs = fb.apply(size);
 112         int[] rs = fr.apply(size);
 113 
 114         for (int i = 0; i < as.length; i++) {
 115             int a = as[i];
 116             int b = bs[i];
 117             rs[i] = (int)(a - b);
 118         }
 119 
 120         return rs;
 121     }
 122 
 123     @Benchmark
 124     public Object subMasked() {
 125         int[] as = fa.apply(size);
 126         int[] bs = fb.apply(size);
 127         int[] rs = fr.apply(size);
 128         boolean[] ms = fm.apply(size);
 129 
 130         for (int i = 0; i < as.length; i++) {
 131             int a = as[i];
 132             int b = bs[i];
 133             if (ms[i % ms.length]) {
 134                 rs[i] = (int)(a - b);
 135             } else {
 136                 rs[i] = a;
 137             }
 138         }
 139         return rs;
 140     }
 141 
 142 
 143 
 144     @Benchmark
 145     public Object mul() {
 146         int[] as = fa.apply(size);
 147         int[] bs = fb.apply(size);
 148         int[] rs = fr.apply(size);
 149 
 150         for (int i = 0; i < as.length; i++) {
 151             int a = as[i];
 152             int b = bs[i];
 153             rs[i] = (int)(a * b);
 154         }
 155 
 156         return rs;
 157     }
 158 
 159     @Benchmark
 160     public Object mulMasked() {
 161         int[] as = fa.apply(size);
 162         int[] bs = fb.apply(size);
 163         int[] rs = fr.apply(size);
 164         boolean[] ms = fm.apply(size);
 165 
 166         for (int i = 0; i < as.length; i++) {
 167             int a = as[i];
 168             int b = bs[i];
 169             if (ms[i % ms.length]) {
 170                 rs[i] = (int)(a * b);
 171             } else {
 172                 rs[i] = a;
 173             }
 174         }
 175         return rs;
 176     }
 177 
 178 
 179     @Benchmark
 180     public Object and() {
 181         int[] as = fa.apply(size);
 182         int[] bs = fb.apply(size);
 183         int[] rs = fr.apply(size);
 184 
 185         for (int i = 0; i < as.length; i++) {
 186             int a = as[i];
 187             int b = bs[i];
 188             rs[i] = (int)(a & b);
 189         }
 190 
 191         return rs;
 192     }
 193 
 194 
 195 
 196     @Benchmark
 197     public Object andMasked() {
 198         int[] as = fa.apply(size);
 199         int[] bs = fb.apply(size);
 200         int[] rs = fr.apply(size);
 201         boolean[] ms = fm.apply(size);
 202 
 203         for (int i = 0; i < as.length; i++) {
 204             int a = as[i];
 205             int b = bs[i];
 206             if (ms[i % ms.length]) {
 207                 rs[i] = (int)(a & b);
 208             } else {
 209                 rs[i] = a;
 210             }
 211         }
 212         return rs;
 213     }
 214 
 215 
 216 
 217     @Benchmark
 218     public Object or() {
 219         int[] as = fa.apply(size);
 220         int[] bs = fb.apply(size);
 221         int[] rs = fr.apply(size);
 222 
 223         for (int i = 0; i < as.length; i++) {
 224             int a = as[i];
 225             int b = bs[i];
 226             rs[i] = (int)(a | b);
 227         }
 228 
 229         return rs;
 230     }
 231 
 232 
 233 
 234     @Benchmark
 235     public Object orMasked() {
 236         int[] as = fa.apply(size);
 237         int[] bs = fb.apply(size);
 238         int[] rs = fr.apply(size);
 239         boolean[] ms = fm.apply(size);
 240 
 241         for (int i = 0; i < as.length; i++) {
 242             int a = as[i];
 243             int b = bs[i];
 244             if (ms[i % ms.length]) {
 245                 rs[i] = (int)(a | b);
 246             } else {
 247                 rs[i] = a;
 248             }
 249         }
 250         return rs;
 251     }
 252 
 253 
 254 
 255     @Benchmark
 256     public Object xor() {
 257         int[] as = fa.apply(size);
 258         int[] bs = fb.apply(size);
 259         int[] rs = fr.apply(size);
 260 
 261         for (int i = 0; i < as.length; i++) {
 262             int a = as[i];
 263             int b = bs[i];
 264             rs[i] = (int)(a ^ b);
 265         }
 266 
 267         return rs;
 268     }
 269 
 270 
 271 
 272     @Benchmark
 273     public Object xorMasked() {
 274         int[] as = fa.apply(size);
 275         int[] bs = fb.apply(size);
 276         int[] rs = fr.apply(size);
 277         boolean[] ms = fm.apply(size);
 278 
 279         for (int i = 0; i < as.length; i++) {
 280             int a = as[i];
 281             int b = bs[i];
 282             if (ms[i % ms.length]) {
 283                 rs[i] = (int)(a ^ b);
 284             } else {
 285                 rs[i] = a;
 286             }
 287         }
 288         return rs;
 289     }
 290 
 291 
 292 
 293     @Benchmark
 294     public Object shiftR() {
 295         int[] as = fa.apply(size);
 296         int[] bs = fb.apply(size);
 297         int[] rs = fr.apply(size);
 298 
 299         for (int i = 0; i < as.length; i++) {
 300             int a = as[i];
 301             int b = bs[i];
 302             rs[i] = (int)((a >>> b));
 303         }
 304 
 305         return rs;
 306     }
 307 
 308 
 309 
 310     @Benchmark
 311     public Object shiftRMasked() {
 312         int[] as = fa.apply(size);
 313         int[] bs = fb.apply(size);
 314         int[] rs = fr.apply(size);
 315         boolean[] ms = fm.apply(size);
 316 
 317         for (int i = 0; i < as.length; i++) {
 318             int a = as[i];
 319             int b = bs[i];
 320             if (ms[i % ms.length]) {
 321                 rs[i] = (int)((a >>> b));
 322             } else {
 323                 rs[i] = a;
 324             }
 325         }
 326         return rs;
 327     }
 328 
 329 
 330 
 331     @Benchmark
 332     public Object shiftL() {
 333         int[] as = fa.apply(size);
 334         int[] bs = fb.apply(size);
 335         int[] rs = fr.apply(size);
 336 
 337         for (int i = 0; i < as.length; i++) {
 338             int a = as[i];
 339             int b = bs[i];
 340             rs[i] = (int)((a << b));
 341         }
 342 
 343         return rs;
 344     }
 345 
 346 
 347 
 348     @Benchmark
 349     public Object shiftLMasked() {
 350         int[] as = fa.apply(size);
 351         int[] bs = fb.apply(size);
 352         int[] rs = fr.apply(size);
 353         boolean[] ms = fm.apply(size);
 354 
 355         for (int i = 0; i < as.length; i++) {
 356             int a = as[i];
 357             int b = bs[i];
 358             if (ms[i % ms.length]) {
 359                 rs[i] = (int)((a << b));
 360             } else {
 361                 rs[i] = a;
 362             }
 363         }
 364         return rs;
 365     }
 366 
 367 
 368 
 369     @Benchmark
 370     public Object aShiftR() {
 371         int[] as = fa.apply(size);
 372         int[] bs = fb.apply(size);
 373         int[] rs = fr.apply(size);
 374 
 375         for (int i = 0; i < as.length; i++) {
 376             int a = as[i];
 377             int b = bs[i];
 378             rs[i] = (int)((a >> b));
 379         }
 380 
 381         return rs;
 382     }
 383 
 384 
 385 
 386     @Benchmark
 387     public Object aShiftRMasked() {
 388         int[] as = fa.apply(size);
 389         int[] bs = fb.apply(size);
 390         int[] rs = fr.apply(size);
 391         boolean[] ms = fm.apply(size);
 392 
 393         for (int i = 0; i < as.length; i++) {
 394             int a = as[i];
 395             int b = bs[i];
 396             if (ms[i % ms.length]) {
 397                 rs[i] = (int)((a >> b));
 398             } else {
 399                 rs[i] = a;
 400             }
 401         }
 402         return rs;
 403     }
 404 
 405 
 406 
 407     @Benchmark
 408     public Object aShiftRShift() {
 409         int[] as = fa.apply(size);
 410         int[] bs = fb.apply(size);
 411         int[] rs = fr.apply(size);
 412 
 413         for (int i = 0; i < as.length; i++) {
 414             int a = as[i];
 415             int b = bs[i];
 416             rs[i] = (int)((a >> b));
 417         }
 418 
 419         return rs;
 420     }
 421 
 422 
 423 
 424     @Benchmark
 425     public Object aShiftRMaskedShift() {
 426         int[] as = fa.apply(size);
 427         int[] bs = fb.apply(size);
 428         int[] rs = fr.apply(size);
 429         boolean[] ms = fm.apply(size);
 430 
 431         for (int i = 0; i < as.length; i++) {
 432             int a = as[i];
 433             int b = bs[i];
 434             boolean m = ms[i % ms.length];
 435             rs[i] = (m ? (int)((a >> b)) : a);
 436         }
 437 
 438         return rs;
 439     }
 440 
 441 
 442 
 443     @Benchmark
 444     public Object shiftRShift() {
 445         int[] as = fa.apply(size);
 446         int[] bs = fb.apply(size);
 447         int[] rs = fr.apply(size);
 448 
 449         for (int i = 0; i < as.length; i++) {
 450             int a = as[i];
 451             int b = bs[i];
 452             rs[i] = (int)((a >>> b));
 453         }
 454 
 455         return rs;
 456     }
 457 
 458 
 459 
 460     @Benchmark
 461     public Object shiftRMaskedShift() {
 462         int[] as = fa.apply(size);
 463         int[] bs = fb.apply(size);
 464         int[] rs = fr.apply(size);
 465         boolean[] ms = fm.apply(size);
 466 
 467         for (int i = 0; i < as.length; i++) {
 468             int a = as[i];
 469             int b = bs[i];
 470             boolean m = ms[i % ms.length];
 471             rs[i] = (m ? (int)((a >>> b)) : a);
 472         }
 473 
 474         return rs;
 475     }
 476 
 477 
 478 
 479     @Benchmark
 480     public Object shiftLShift() {
 481         int[] as = fa.apply(size);
 482         int[] bs = fb.apply(size);
 483         int[] rs = fr.apply(size);
 484 
 485         for (int i = 0; i < as.length; i++) {
 486             int a = as[i];
 487             int b = bs[i];
 488             rs[i] = (int)((a << b));
 489         }
 490 
 491         return rs;
 492     }
 493 
 494 
 495 
 496     @Benchmark
 497     public Object shiftLMaskedShift() {
 498         int[] as = fa.apply(size);
 499         int[] bs = fb.apply(size);
 500         int[] rs = fr.apply(size);
 501         boolean[] ms = fm.apply(size);
 502 
 503         for (int i = 0; i < as.length; i++) {
 504             int a = as[i];
 505             int b = bs[i];
 506             boolean m = ms[i % ms.length];
 507             rs[i] = (m ? (int)((a << b)) : a);
 508         }
 509 
 510         return rs;
 511     }
 512 
 513 
 514 
 515 
 516 
 517 
 518 
 519 
 520 
 521 
 522 
 523 
 524 
 525 
 526     @Benchmark
 527     public Object max() {
 528         int[] as = fa.apply(size);
 529         int[] bs = fb.apply(size);
 530         int[] rs = fr.apply(size);
 531 
 532         for (int i = 0; i < as.length; i++) {
 533             int a = as[i];
 534             int b = bs[i];
 535             rs[i] = (int)(Math.max(a, b));
 536         }
 537 
 538         return rs;
 539     }
 540 
 541     @Benchmark
 542     public Object min() {
 543         int[] as = fa.apply(size);
 544         int[] bs = fb.apply(size);
 545         int[] rs = fr.apply(size);
 546 
 547         for (int i = 0; i < as.length; i++) {
 548             int a = as[i];
 549             int b = bs[i];
 550             rs[i] = (int)(Math.min(a, b));
 551         }
 552 
 553         return rs;
 554     }
 555 
 556 
 557     @Benchmark
 558     public int andAll() {
 559         int[] as = fa.apply(size);
 560         int r = -1;
 561         for (int i = 0; i < as.length; i++) {
 562             r &= as[i];
 563         }
 564         return r;
 565     }
 566 
 567 
 568 
 569     @Benchmark
 570     public int orAll() {
 571         int[] as = fa.apply(size);
 572         int r = 0;
 573         for (int i = 0; i < as.length; i++) {
 574             r |= as[i];
 575         }
 576         return r;
 577     }
 578 
 579 
 580 
 581     @Benchmark
 582     public int xorAll() {
 583         int[] as = fa.apply(size);
 584         int r = 0;
 585         for (int i = 0; i < as.length; i++) {
 586             r ^= as[i];
 587         }
 588         return r;
 589     }
 590 
 591 
 592     @Benchmark
 593     public int addAll() {
 594         int[] as = fa.apply(size);
 595         int r = 0;
 596         for (int i = 0; i < as.length; i++) {
 597             r += as[i];
 598         }
 599         return r;
 600     }
 601 
 602     @Benchmark
 603     public int mulAll() {
 604         int[] as = fa.apply(size);
 605         int r = 1;
 606         for (int i = 0; i < as.length; i++) {
 607             r *= as[i];
 608         }
 609         return r;
 610     }
 611 
 612     @Benchmark
 613     public int minAll() {
 614         int[] as = fa.apply(size);
 615         int r = Integer.MAX_VALUE;
 616         for (int i = 0; i < as.length; i++) {
 617             r = (int)Math.min(r, as[i]);
 618         }
 619         return r;
 620     }
 621 
 622     @Benchmark
 623     public int maxAll() {
 624         int[] as = fa.apply(size);
 625         int r = Integer.MIN_VALUE;
 626         for (int i = 0; i < as.length; i++) {
 627             r = (int)Math.max(r, as[i]);
 628         }
 629         return r;
 630     }
 631 
 632 
 633     @Benchmark
 634     public boolean anyTrue() {
 635         boolean[] ms = fm.apply(size);
 636         boolean r = false;
 637         for (int i = 0; i < ms.length; i++) {
 638             r |= ms[i];
 639         }
 640         return r;
 641     }
 642 
 643 
 644 
 645     @Benchmark
 646     public boolean allTrue() {
 647         boolean[] ms = fm.apply(size);
 648         boolean r = true;
 649         for (int i = 0; i < ms.length; i++) {
 650             r &= ms[i];
 651         }
 652         return r;
 653     }
 654 
 655 
 656     @Benchmark
 657     public boolean lessThan() {
 658         int[] as = fa.apply(size);
 659         int[] bs = fb.apply(size);
 660 
 661         boolean r = false;
 662         for (int i = 0; i < as.length; i++) {
 663             boolean m = (as[i] < bs[i]);
 664             r |= m; // accumulate so JIT can't eliminate the computation
 665         }
 666 
 667         return r;
 668     }
 669 
 670     @Benchmark
 671     public boolean greaterThan() {
 672         int[] as = fa.apply(size);
 673         int[] bs = fb.apply(size);
 674 
 675         boolean r = false;
 676         for (int i = 0; i < as.length; i++) {
 677             boolean m = (as[i] > bs[i]);
 678             r |= m; // accumulate so JIT can't eliminate the computation
 679         }
 680 
 681         return r;
 682     }
 683 
 684     @Benchmark
 685     public boolean equal() {
 686         int[] as = fa.apply(size);
 687         int[] bs = fb.apply(size);
 688 
 689         boolean r = false;
 690         for (int i = 0; i < as.length; i++) {
 691             boolean m = (as[i] == bs[i]);
 692             r |= m; // accumulate so JIT can't eliminate the computation
 693         }
 694 
 695         return r;
 696     }
 697 
 698     @Benchmark
 699     public boolean notEqual() {
 700         int[] as = fa.apply(size);
 701         int[] bs = fb.apply(size);
 702 
 703         boolean r = false;
 704         for (int i = 0; i < as.length; i++) {
 705             boolean m = (as[i] != bs[i]);
 706             r |= m; // accumulate so JIT can't eliminate the computation
 707         }
 708 
 709         return r;
 710     }
 711 
 712     @Benchmark
 713     public boolean lessThanEq() {
 714         int[] as = fa.apply(size);
 715         int[] bs = fb.apply(size);
 716 
 717         boolean r = false;
 718         for (int i = 0; i < as.length; i++) {
 719             boolean m = (as[i] <= bs[i]);
 720             r |= m; // accumulate so JIT can't eliminate the computation
 721         }
 722 
 723         return r;
 724     }
 725 
 726     @Benchmark
 727     public boolean greaterThanEq() {
 728         int[] as = fa.apply(size);
 729         int[] bs = fb.apply(size);
 730 
 731         boolean r = false;
 732         for (int i = 0; i < as.length; i++) {
 733             boolean m = (as[i] >= bs[i]);
 734             r |= m; // accumulate so JIT can't eliminate the computation
 735         }
 736 
 737         return r;
 738     }
 739 
 740     @Benchmark
 741     public Object blend() {
 742         int[] as = fa.apply(size);
 743         int[] bs = fb.apply(size);
 744         int[] rs = fr.apply(size);
 745         boolean[] ms = fm.apply(size);
 746 
 747         for (int i = 0; i < as.length; i++) {
 748             int a = as[i];
 749             int b = bs[i];
 750             boolean m = ms[i % ms.length];
 751             rs[i] = (m ? b : a);
 752         }
 753 
 754         return rs;
 755     }
 756     Object rearrangeShared(int window) {
 757         int[] as = fa.apply(size);
 758         int[] order = fs.apply(size);
 759         int[] rs = fr.apply(size);
 760 
 761         for (int i = 0; i < as.length; i += window) {
 762             for (int j = 0; j < window; j++) {
 763                 int a = as[i+j];
 764                 int pos = order[j];
 765                 rs[i + pos] = a;
 766             }
 767         }
 768 
 769         return rs;
 770     }
 771 
 772     @Benchmark
 773     public Object rearrange064() {
 774         int window = 64 / Integer.SIZE;
 775         return rearrangeShared(window);
 776     }
 777 
 778     @Benchmark
 779     public Object rearrange128() {
 780         int window = 128 / Integer.SIZE;
 781         return rearrangeShared(window);
 782     }
 783 
 784     @Benchmark
 785     public Object rearrange256() {
 786         int window = 256 / Integer.SIZE;
 787         return rearrangeShared(window);
 788     }
 789 
 790     @Benchmark
 791     public Object rearrange512() {
 792         int window = 512 / Integer.SIZE;
 793         return rearrangeShared(window);
 794     }
 795 
 796 
 797 
 798 
 799 
 800 
 801 
 802 
 803 
 804 
 805 
 806 
 807 
 808 
 809 
 810 
 811 
 812 
 813 
 814 
 815 
 816     @Benchmark
 817     public Object neg() {
 818         int[] as = fa.apply(size);
 819         int[] rs = fr.apply(size);
 820 
 821         for (int i = 0; i < as.length; i++) {
 822             int a = as[i];
 823             rs[i] = (int)(-((int)a));
 824         }
 825 
 826         return rs;
 827     }
 828 
 829     @Benchmark
 830     public Object negMasked() {
 831         int[] as = fa.apply(size);
 832         int[] rs = fr.apply(size);
 833         boolean[] ms = fm.apply(size);
 834 
 835         for (int i = 0; i < as.length; i++) {
 836             int a = as[i];
 837             boolean m = ms[i % ms.length];
 838             rs[i] = (m ? (int)(-((int)a)) : a);
 839         }
 840 
 841         return rs;
 842     }
 843 
 844     @Benchmark
 845     public Object abs() {
 846         int[] as = fa.apply(size);
 847         int[] rs = fr.apply(size);
 848 
 849         for (int i = 0; i < as.length; i++) {
 850             int a = as[i];
 851             rs[i] = (int)(Math.abs((int)a));
 852         }
 853 
 854         return rs;
 855     }
 856 
 857     @Benchmark
 858     public Object absMasked() {
 859         int[] as = fa.apply(size);
 860         int[] rs = fr.apply(size);
 861         boolean[] ms = fm.apply(size);
 862 
 863         for (int i = 0; i < as.length; i++) {
 864             int a = as[i];
 865             boolean m = ms[i % ms.length];
 866             rs[i] = (m ? (int)(Math.abs((int)a)) : a);
 867         }
 868 
 869         return rs;
 870     }
 871 
 872 
 873     @Benchmark
 874     public Object not() {
 875         int[] as = fa.apply(size);
 876         int[] rs = fr.apply(size);
 877 
 878         for (int i = 0; i < as.length; i++) {
 879             int a = as[i];
 880             rs[i] = (int)(~((int)a));
 881         }
 882 
 883         return rs;
 884     }
 885 
 886 
 887 
 888     @Benchmark
 889     public Object notMasked() {
 890         int[] as = fa.apply(size);
 891         int[] rs = fr.apply(size);
 892         boolean[] ms = fm.apply(size);
 893 
 894         for (int i = 0; i < as.length; i++) {
 895             int a = as[i];
 896             boolean m = ms[i % ms.length];
 897             rs[i] = (m ? (int)(~((int)a)) : a);
 898         }
 899 
 900         return rs;
 901     }
 902 
 903 
 904 
 905 
 906     @Benchmark
 907     public Object gatherBase0() {
 908         int[] as = fa.apply(size);
 909         int[] is    = fs.apply(size);
 910         int[] rs = fr.apply(size);
 911 
 912         for (int i = 0; i < as.length; i++) {
 913             int ix = 0 + is[i];
 914             rs[i] = as[ix];
 915         }
 916 
 917         return rs;
 918     }
 919 
 920 
 921     Object gather(int window) {
 922         int[] as = fa.apply(size);
 923         int[] is    = fs.apply(size);
 924         int[] rs = fr.apply(size);
 925 
 926         for (int i = 0; i < as.length; i += window) {
 927             for (int j = 0; j < window; j++) {
 928                 int ix = i + is[i + j];
 929                 rs[i + j] = as[ix];
 930             }
 931         }
 932 
 933         return rs;
 934     }
 935 
 936     @Benchmark
 937     public Object gather064() {
 938         int window = 64 / Integer.SIZE;
 939         return gather(window);
 940     }
 941 
 942     @Benchmark
 943     public Object gather128() {
 944         int window = 128 / Integer.SIZE;
 945         return gather(window);
 946     }
 947 
 948     @Benchmark
 949     public Object gather256() {
 950         int window = 256 / Integer.SIZE;
 951         return gather(window);
 952     }
 953 
 954     @Benchmark
 955     public Object gather512() {
 956         int window = 512 / Integer.SIZE;
 957         return gather(window);
 958     }
 959 
 960 
 961 
 962     @Benchmark
 963     public Object scatterBase0() {
 964         int[] as = fa.apply(size);
 965         int[] is    = fs.apply(size);
 966         int[] rs = fr.apply(size);
 967 
 968         for (int i = 0; i < as.length; i++) {
 969             int ix = 0 + is[i];
 970             rs[ix] = as[i];
 971         }
 972 
 973         return rs;
 974     }
 975 
 976     Object scatter(int window) {
 977         int[] as = fa.apply(size);
 978         int[] is    = fs.apply(size);
 979         int[] rs = fr.apply(size);
 980 
 981         for (int i = 0; i < as.length; i += window) {
 982             for (int j = 0; j < window; j++) {
 983                 int ix = i + is[i + j];
 984                 rs[ix] = as[i + j];
 985             }
 986         }
 987 
 988         return rs;
 989     }
 990 
 991     @Benchmark
 992     public Object scatter064() {
 993         int window = 64 / Integer.SIZE;
 994         return scatter(window);
 995     }
 996 
 997     @Benchmark
 998     public Object scatter128() {
 999         int window = 128 / Integer.SIZE;
1000         return scatter(window);
1001     }
1002 
1003     @Benchmark
1004     public Object scatter256() {
1005         int window = 256 / Integer.SIZE;
1006         return scatter(window);
1007     }
1008 
1009     @Benchmark
1010     public Object scatter512() {
1011         int window = 512 / Integer.SIZE;
1012         return scatter(window);
1013     }
1014 
1015 }
1016