< prev index next >

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

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


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

  29 import jdk.incubator.vector.ShortVector;
  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 ShortMaxVector extends AbstractVectorBenchmark {
  45     static final Species<Short> SPECIES = ShortVector.SPECIES_MAX;
  46 
  47     static final int INVOC_COUNT = 1; // get rid of outer loop
  48 
  49     @Param("1024")
  50     int size;
  51 
  52     short[] fill(IntFunction<Short> f) {
  53         short[] array = new short[size];
  54         for (int i = 0; i < array.length; i++) {
  55             array[i] = f.apply(i);
  56         }
  57         return array;
  58     }
  59 
  60     short[] a, b, c, r;
  61     boolean[] m, rm;
  62     int[] s;
  63 
  64     @Setup
  65     public void init() {


  91         short[] b = fb.apply(SPECIES.length());
  92         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
  97                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 108         short[] b = fb.apply(SPECIES.length());
 109         short[] r = fr.apply(SPECIES.length());
 110         boolean[] mask = fm.apply(SPECIES.length());
 111         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 116                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 127         short[] b = fb.apply(SPECIES.length());
 128         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 133                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 144         short[] b = fb.apply(SPECIES.length());
 145         short[] r = fr.apply(SPECIES.length());
 146         boolean[] mask = fm.apply(SPECIES.length());
 147         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 152                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 165         short[] b = fb.apply(SPECIES.length());
 166         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 171                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 182         short[] b = fb.apply(SPECIES.length());
 183         short[] r = fr.apply(SPECIES.length());
 184         boolean[] mask = fm.apply(SPECIES.length());
 185         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 190                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 202         short[] b = fb.apply(SPECIES.length());
 203         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 208                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 221         short[] b = fb.apply(SPECIES.length());
 222         short[] r = fr.apply(SPECIES.length());
 223         boolean[] mask = fm.apply(SPECIES.length());
 224         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 229                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 242         short[] b = fb.apply(SPECIES.length());
 243         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 248                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 261         short[] b = fb.apply(SPECIES.length());
 262         short[] r = fr.apply(SPECIES.length());
 263         boolean[] mask = fm.apply(SPECIES.length());
 264         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 269                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 282         short[] b = fb.apply(SPECIES.length());
 283         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 288                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 301         short[] b = fb.apply(SPECIES.length());
 302         short[] r = fr.apply(SPECIES.length());
 303         boolean[] mask = fm.apply(SPECIES.length());
 304         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 309                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 310                 av.xor(bv, vmask).intoArray(r, i);
 311             }
 312         }
 313 
 314         bh.consume(r);
 315     }
 316 
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 


 341         short[] r = fr.apply(SPECIES.length());
 342 
 343         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 344             for (int i = 0; i < a.length; i += SPECIES.length()) {
 345                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 346                 av.aShiftR((int)b[i]).intoArray(r, i);
 347             }
 348         }
 349 
 350         bh.consume(r);
 351     }
 352 
 353 
 354 
 355     @Benchmark
 356     public void aShiftRMaskedShift(Blackhole bh) {
 357         short[] a = fa.apply(SPECIES.length());
 358         short[] b = fb.apply(SPECIES.length());
 359         short[] r = fr.apply(SPECIES.length());
 360         boolean[] mask = fm.apply(SPECIES.length());
 361         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 362 
 363         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 364             for (int i = 0; i < a.length; i += SPECIES.length()) {
 365                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 366                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 367             }
 368         }
 369 
 370         bh.consume(r);
 371     }
 372 
 373 
 374 
 375     @Benchmark
 376     public void shiftLShift(Blackhole bh) {
 377         short[] a = fa.apply(SPECIES.length());
 378         short[] b = fb.apply(SPECIES.length());
 379         short[] r = fr.apply(SPECIES.length());
 380 
 381         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 382             for (int i = 0; i < a.length; i += SPECIES.length()) {
 383                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 384                 av.shiftL((int)b[i]).intoArray(r, i);
 385             }
 386         }
 387 
 388         bh.consume(r);
 389     }
 390 
 391 
 392 
 393     @Benchmark
 394     public void shiftLMaskedShift(Blackhole bh) {
 395         short[] a = fa.apply(SPECIES.length());
 396         short[] b = fb.apply(SPECIES.length());
 397         short[] r = fr.apply(SPECIES.length());
 398         boolean[] mask = fm.apply(SPECIES.length());
 399         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 400 
 401         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 402             for (int i = 0; i < a.length; i += SPECIES.length()) {
 403                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 404                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 405             }
 406         }
 407 
 408         bh.consume(r);
 409     }
 410 
 411 
 412 
 413     @Benchmark
 414     public void shiftRShift(Blackhole bh) {
 415         short[] a = fa.apply(SPECIES.length());
 416         short[] b = fb.apply(SPECIES.length());
 417         short[] r = fr.apply(SPECIES.length());
 418 
 419         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 420             for (int i = 0; i < a.length; i += SPECIES.length()) {
 421                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 422                 av.shiftR((int)b[i]).intoArray(r, i);
 423             }
 424         }
 425 
 426         bh.consume(r);
 427     }
 428 
 429 
 430 
 431     @Benchmark
 432     public void shiftRMaskedShift(Blackhole bh) {
 433         short[] a = fa.apply(SPECIES.length());
 434         short[] b = fb.apply(SPECIES.length());
 435         short[] r = fr.apply(SPECIES.length());
 436         boolean[] mask = fm.apply(SPECIES.length());
 437         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 438 
 439         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 440             for (int i = 0; i < a.length; i += SPECIES.length()) {
 441                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 442                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 443             }
 444         }
 445 
 446         bh.consume(r);
 447     }
 448 
 449 
 450     @Benchmark
 451     public void max(Blackhole bh) {
 452         short[] a = fa.apply(SPECIES.length());
 453         short[] b = fb.apply(SPECIES.length());
 454         short[] r = fr.apply(SPECIES.length());
 455 
 456         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 457             for (int i = 0; i < a.length; i += SPECIES.length()) {


 583         short ra = Short.MIN_VALUE;
 584 
 585         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 586             ra = Short.MIN_VALUE;
 587             for (int i = 0; i < a.length; i += SPECIES.length()) {
 588                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 589                 ra = (short)Math.max(ra, av.maxAll());
 590             }
 591         }
 592         bh.consume(ra);
 593     }
 594 
 595 
 596     @Benchmark
 597     public void anyTrue(Blackhole bh) {
 598         boolean[] mask = fm.apply(SPECIES.length());
 599         boolean[] r = fmr.apply(SPECIES.length());
 600 
 601         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 602             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 603                 Vector.Mask<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i);
 604                 r[i] = vmask.anyTrue();
 605             }
 606         }
 607 
 608         bh.consume(r);
 609     }
 610 
 611 
 612 
 613     @Benchmark
 614     public void allTrue(Blackhole bh) {
 615         boolean[] mask = fm.apply(SPECIES.length());
 616         boolean[] r = fmr.apply(SPECIES.length());
 617 
 618         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 619             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 620                 Vector.Mask<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i);
 621                 r[i] = vmask.allTrue();
 622             }
 623         }
 624 
 625         bh.consume(r);
 626     }
 627 
 628 
 629     @Benchmark
 630     public void with(Blackhole bh) {
 631         short[] a = fa.apply(SPECIES.length());
 632         short[] r = fr.apply(SPECIES.length());
 633 
 634         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 635             for (int i = 0; i < a.length; i += SPECIES.length()) {
 636                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 637                 av.with(0, (short)4).intoArray(r, i);
 638             }
 639         }
 640 
 641         bh.consume(r);
 642     }
 643 
 644     @Benchmark
 645     public Object lessThan() {
 646         short[] a = fa.apply(size);
 647         short[] b = fb.apply(size);
 648         boolean[] ms = fm.apply(size);
 649         Vector.Mask<Short> m = ShortVector.maskFromArray(SPECIES, ms, 0);
 650 
 651         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 652             for (int i = 0; i < a.length; i += SPECIES.length()) {
 653                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 654                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 655                 Vector.Mask<Short> mv = av.lessThan(bv);
 656 
 657                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 658             }
 659         }
 660         return m;
 661     }
 662 
 663 
 664     @Benchmark
 665     public Object greaterThan() {
 666         short[] a = fa.apply(size);
 667         short[] b = fb.apply(size);
 668         boolean[] ms = fm.apply(size);
 669         Vector.Mask<Short> m = ShortVector.maskFromArray(SPECIES, ms, 0);
 670 
 671         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 672             for (int i = 0; i < a.length; i += SPECIES.length()) {
 673                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 674                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 675                 Vector.Mask<Short> mv = av.greaterThan(bv);
 676 
 677                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 678             }
 679         }
 680         return m;
 681     }
 682 
 683 
 684     @Benchmark
 685     public Object equal() {
 686         short[] a = fa.apply(size);
 687         short[] b = fb.apply(size);
 688         boolean[] ms = fm.apply(size);
 689         Vector.Mask<Short> m = ShortVector.maskFromArray(SPECIES, ms, 0);
 690 
 691         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 692             for (int i = 0; i < a.length; i += SPECIES.length()) {
 693                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 694                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 695                 Vector.Mask<Short> mv = av.equal(bv);
 696 
 697                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 698             }
 699         }
 700         return m;
 701     }
 702 
 703 
 704     @Benchmark
 705     public Object notEqual() {
 706         short[] a = fa.apply(size);
 707         short[] b = fb.apply(size);
 708         boolean[] ms = fm.apply(size);
 709         Vector.Mask<Short> m = ShortVector.maskFromArray(SPECIES, ms, 0);
 710 
 711         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 712             for (int i = 0; i < a.length; i += SPECIES.length()) {
 713                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 714                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 715                 Vector.Mask<Short> mv = av.notEqual(bv);
 716 
 717                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 718             }
 719         }
 720         return m;
 721     }
 722 
 723 
 724     @Benchmark
 725     public Object lessThanEq() {
 726         short[] a = fa.apply(size);
 727         short[] b = fb.apply(size);
 728         boolean[] ms = fm.apply(size);
 729         Vector.Mask<Short> m = ShortVector.maskFromArray(SPECIES, ms, 0);
 730 
 731         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 732             for (int i = 0; i < a.length; i += SPECIES.length()) {
 733                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 734                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 735                 Vector.Mask<Short> mv = av.lessThanEq(bv);
 736 
 737                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 738             }
 739         }
 740         return m;
 741     }
 742 
 743 
 744     @Benchmark
 745     public Object greaterThanEq() {
 746         short[] a = fa.apply(size);
 747         short[] b = fb.apply(size);
 748         boolean[] ms = fm.apply(size);
 749         Vector.Mask<Short> m = ShortVector.maskFromArray(SPECIES, ms, 0);
 750 
 751         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 752             for (int i = 0; i < a.length; i += SPECIES.length()) {
 753                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 754                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 755                 Vector.Mask<Short> mv = av.greaterThanEq(bv);
 756 
 757                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 758             }
 759         }
 760         return m;
 761     }
 762 
 763 
 764     @Benchmark
 765     public void blend(Blackhole bh) {
 766         short[] a = fa.apply(SPECIES.length());
 767         short[] b = fb.apply(SPECIES.length());
 768         short[] r = fr.apply(SPECIES.length());
 769         boolean[] mask = fm.apply(SPECIES.length());
 770         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 771 
 772         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 773             for (int i = 0; i < a.length; i += SPECIES.length()) {
 774                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 775                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 776                 av.blend(bv, vmask).intoArray(r, i);
 777             }
 778         }
 779 
 780         bh.consume(r);
 781     }
 782 
 783     @Benchmark
 784     public void rearrange(Blackhole bh) {
 785         short[] a = fa.apply(SPECIES.length());
 786         int[] order = fs.apply(a.length, SPECIES.length());
 787         short[] r = fr.apply(SPECIES.length());
 788 
 789         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 790             for (int i = 0; i < a.length; i += SPECIES.length()) {
 791                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 792                 av.rearrange(ShortVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
 793             }
 794         }
 795 
 796         bh.consume(r);
 797     }
 798 
 799     @Benchmark
 800     public void extract(Blackhole bh) {
 801         short[] a = fa.apply(SPECIES.length());
 802         short[] r = fr.apply(SPECIES.length());
 803 
 804         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 805             for (int i = 0; i < a.length; i += SPECIES.length()) {
 806                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 807                 int num_lanes = SPECIES.length();
 808                 // Manually unroll because full unroll happens after intrinsification.
 809                 // Unroll is needed because get intrinsic requires for index to be a known constant.
 810                 if (num_lanes == 1) {
 811                     r[i]=av.get(0);
 812                 } else if (num_lanes == 2) {


 975     @Benchmark
 976     public void neg(Blackhole bh) {
 977         short[] a = fa.apply(SPECIES.length());
 978         short[] r = fr.apply(SPECIES.length());
 979 
 980         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 981             for (int i = 0; i < a.length; i += SPECIES.length()) {
 982                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 983                 av.neg().intoArray(r, i);
 984             }
 985         }
 986 
 987         bh.consume(r);
 988     }
 989 
 990     @Benchmark
 991     public void negMasked(Blackhole bh) {
 992         short[] a = fa.apply(SPECIES.length());
 993         short[] r = fr.apply(SPECIES.length());
 994         boolean[] mask = fm.apply(SPECIES.length());
 995         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 996 
 997         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 998             for (int i = 0; i < a.length; i += SPECIES.length()) {
 999                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1000                 av.neg(vmask).intoArray(r, i);
1001             }
1002         }
1003 
1004         bh.consume(r);
1005     }
1006 
1007     @Benchmark
1008     public void abs(Blackhole bh) {
1009         short[] a = fa.apply(SPECIES.length());
1010         short[] r = fr.apply(SPECIES.length());
1011 
1012         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1013             for (int i = 0; i < a.length; i += SPECIES.length()) {
1014                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1015                 av.abs().intoArray(r, i);
1016             }
1017         }
1018 
1019         bh.consume(r);
1020     }
1021 
1022     @Benchmark
1023     public void absMasked(Blackhole bh) {
1024         short[] a = fa.apply(SPECIES.length());
1025         short[] r = fr.apply(SPECIES.length());
1026         boolean[] mask = fm.apply(SPECIES.length());
1027         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
1028 
1029         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1030             for (int i = 0; i < a.length; i += SPECIES.length()) {
1031                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1032                 av.abs(vmask).intoArray(r, i);
1033             }
1034         }
1035 
1036         bh.consume(r);
1037     }
1038 
1039 
1040     @Benchmark
1041     public void not(Blackhole bh) {
1042         short[] a = fa.apply(SPECIES.length());
1043         short[] r = fr.apply(SPECIES.length());
1044 
1045         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1046             for (int i = 0; i < a.length; i += SPECIES.length()) {
1047                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1048                 av.not().intoArray(r, i);
1049             }
1050         }
1051 
1052         bh.consume(r);
1053     }
1054 
1055 
1056 
1057     @Benchmark
1058     public void notMasked(Blackhole bh) {
1059         short[] a = fa.apply(SPECIES.length());
1060         short[] r = fr.apply(SPECIES.length());
1061         boolean[] mask = fm.apply(SPECIES.length());
1062         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
1063 
1064         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1065             for (int i = 0; i < a.length; i += SPECIES.length()) {
1066                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1067                 av.not(vmask).intoArray(r, i);
1068             }
1069         }
1070 
1071         bh.consume(r);
1072     }
1073 
1074 
1075 
1076 
1077 
1078 }
1079 


   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.ShortVector;
  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 ShortMaxVector extends AbstractVectorBenchmark {
  46     static final VectorSpecies<Short> SPECIES = ShortVector.SPECIES_MAX;
  47 
  48     static final int INVOC_COUNT = 1; // get rid of outer loop
  49 
  50     @Param("1024")
  51     int size;
  52 
  53     short[] fill(IntFunction<Short> f) {
  54         short[] array = new short[size];
  55         for (int i = 0; i < array.length; i++) {
  56             array[i] = f.apply(i);
  57         }
  58         return array;
  59     }
  60 
  61     short[] a, b, c, r;
  62     boolean[] m, rm;
  63     int[] s;
  64 
  65     @Setup
  66     public void init() {


  92         short[] b = fb.apply(SPECIES.length());
  93         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
  98                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 109         short[] b = fb.apply(SPECIES.length());
 110         short[] r = fr.apply(SPECIES.length());
 111         boolean[] mask = fm.apply(SPECIES.length());
 112         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 117                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 128         short[] b = fb.apply(SPECIES.length());
 129         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 134                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 145         short[] b = fb.apply(SPECIES.length());
 146         short[] r = fr.apply(SPECIES.length());
 147         boolean[] mask = fm.apply(SPECIES.length());
 148         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 153                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 166         short[] b = fb.apply(SPECIES.length());
 167         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 172                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 183         short[] b = fb.apply(SPECIES.length());
 184         short[] r = fr.apply(SPECIES.length());
 185         boolean[] mask = fm.apply(SPECIES.length());
 186         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 191                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 203         short[] b = fb.apply(SPECIES.length());
 204         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 209                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 222         short[] b = fb.apply(SPECIES.length());
 223         short[] r = fr.apply(SPECIES.length());
 224         boolean[] mask = fm.apply(SPECIES.length());
 225         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 230                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 243         short[] b = fb.apply(SPECIES.length());
 244         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 249                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 262         short[] b = fb.apply(SPECIES.length());
 263         short[] r = fr.apply(SPECIES.length());
 264         boolean[] mask = fm.apply(SPECIES.length());
 265         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 270                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 283         short[] b = fb.apply(SPECIES.length());
 284         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 289                 ShortVector bv = ShortVector.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         short[] a = fa.apply(SPECIES.length());
 302         short[] b = fb.apply(SPECIES.length());
 303         short[] r = fr.apply(SPECIES.length());
 304         boolean[] mask = fm.apply(SPECIES.length());
 305         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 310                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 311                 av.xor(bv, vmask).intoArray(r, i);
 312             }
 313         }
 314 
 315         bh.consume(r);
 316     }
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 
 325 


 342         short[] r = fr.apply(SPECIES.length());
 343 
 344         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 345             for (int i = 0; i < a.length; i += SPECIES.length()) {
 346                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 347                 av.aShiftR((int)b[i]).intoArray(r, i);
 348             }
 349         }
 350 
 351         bh.consume(r);
 352     }
 353 
 354 
 355 
 356     @Benchmark
 357     public void aShiftRMaskedShift(Blackhole bh) {
 358         short[] a = fa.apply(SPECIES.length());
 359         short[] b = fb.apply(SPECIES.length());
 360         short[] r = fr.apply(SPECIES.length());
 361         boolean[] mask = fm.apply(SPECIES.length());
 362         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 363 
 364         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 365             for (int i = 0; i < a.length; i += SPECIES.length()) {
 366                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 367                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 368             }
 369         }
 370 
 371         bh.consume(r);
 372     }
 373 
 374 
 375 
 376     @Benchmark
 377     public void shiftLShift(Blackhole bh) {
 378         short[] a = fa.apply(SPECIES.length());
 379         short[] b = fb.apply(SPECIES.length());
 380         short[] r = fr.apply(SPECIES.length());
 381 
 382         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 383             for (int i = 0; i < a.length; i += SPECIES.length()) {
 384                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 385                 av.shiftL((int)b[i]).intoArray(r, i);
 386             }
 387         }
 388 
 389         bh.consume(r);
 390     }
 391 
 392 
 393 
 394     @Benchmark
 395     public void shiftLMaskedShift(Blackhole bh) {
 396         short[] a = fa.apply(SPECIES.length());
 397         short[] b = fb.apply(SPECIES.length());
 398         short[] r = fr.apply(SPECIES.length());
 399         boolean[] mask = fm.apply(SPECIES.length());
 400         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 401 
 402         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 403             for (int i = 0; i < a.length; i += SPECIES.length()) {
 404                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 405                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 406             }
 407         }
 408 
 409         bh.consume(r);
 410     }
 411 
 412 
 413 
 414     @Benchmark
 415     public void shiftRShift(Blackhole bh) {
 416         short[] a = fa.apply(SPECIES.length());
 417         short[] b = fb.apply(SPECIES.length());
 418         short[] r = fr.apply(SPECIES.length());
 419 
 420         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 421             for (int i = 0; i < a.length; i += SPECIES.length()) {
 422                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 423                 av.shiftR((int)b[i]).intoArray(r, i);
 424             }
 425         }
 426 
 427         bh.consume(r);
 428     }
 429 
 430 
 431 
 432     @Benchmark
 433     public void shiftRMaskedShift(Blackhole bh) {
 434         short[] a = fa.apply(SPECIES.length());
 435         short[] b = fb.apply(SPECIES.length());
 436         short[] r = fr.apply(SPECIES.length());
 437         boolean[] mask = fm.apply(SPECIES.length());
 438         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 439 
 440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 441             for (int i = 0; i < a.length; i += SPECIES.length()) {
 442                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 443                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 444             }
 445         }
 446 
 447         bh.consume(r);
 448     }
 449 
 450 
 451     @Benchmark
 452     public void max(Blackhole bh) {
 453         short[] a = fa.apply(SPECIES.length());
 454         short[] b = fb.apply(SPECIES.length());
 455         short[] r = fr.apply(SPECIES.length());
 456 
 457         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 458             for (int i = 0; i < a.length; i += SPECIES.length()) {


 584         short ra = Short.MIN_VALUE;
 585 
 586         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 587             ra = Short.MIN_VALUE;
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 590                 ra = (short)Math.max(ra, av.maxAll());
 591             }
 592         }
 593         bh.consume(ra);
 594     }
 595 
 596 
 597     @Benchmark
 598     public void anyTrue(Blackhole bh) {
 599         boolean[] mask = fm.apply(SPECIES.length());
 600         boolean[] r = fmr.apply(SPECIES.length());
 601 
 602         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 603             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 604                 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
 605                 r[i] = vmask.anyTrue();
 606             }
 607         }
 608 
 609         bh.consume(r);
 610     }
 611 
 612 
 613 
 614     @Benchmark
 615     public void allTrue(Blackhole bh) {
 616         boolean[] mask = fm.apply(SPECIES.length());
 617         boolean[] r = fmr.apply(SPECIES.length());
 618 
 619         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 620             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 621                 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
 622                 r[i] = vmask.allTrue();
 623             }
 624         }
 625 
 626         bh.consume(r);
 627     }
 628 
 629 
 630     @Benchmark
 631     public void with(Blackhole bh) {
 632         short[] a = fa.apply(SPECIES.length());
 633         short[] r = fr.apply(SPECIES.length());
 634 
 635         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 636             for (int i = 0; i < a.length; i += SPECIES.length()) {
 637                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 638                 av.with(0, (short)4).intoArray(r, i);
 639             }
 640         }
 641 
 642         bh.consume(r);
 643     }
 644 
 645     @Benchmark
 646     public Object lessThan() {
 647         short[] a = fa.apply(size);
 648         short[] b = fb.apply(size);
 649         boolean[] ms = fm.apply(size);
 650         VectorMask<Short> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 651 
 652         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 653             for (int i = 0; i < a.length; i += SPECIES.length()) {
 654                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 655                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 656                 VectorMask<Short> mv = av.lessThan(bv);
 657 
 658                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 659             }
 660         }
 661         return m;
 662     }
 663 
 664 
 665     @Benchmark
 666     public Object greaterThan() {
 667         short[] a = fa.apply(size);
 668         short[] b = fb.apply(size);
 669         boolean[] ms = fm.apply(size);
 670         VectorMask<Short> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 671 
 672         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 673             for (int i = 0; i < a.length; i += SPECIES.length()) {
 674                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 675                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 676                 VectorMask<Short> mv = av.greaterThan(bv);
 677 
 678                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 679             }
 680         }
 681         return m;
 682     }
 683 
 684 
 685     @Benchmark
 686     public Object equal() {
 687         short[] a = fa.apply(size);
 688         short[] b = fb.apply(size);
 689         boolean[] ms = fm.apply(size);
 690         VectorMask<Short> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 691 
 692         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 693             for (int i = 0; i < a.length; i += SPECIES.length()) {
 694                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 695                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 696                 VectorMask<Short> mv = av.equal(bv);
 697 
 698                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 699             }
 700         }
 701         return m;
 702     }
 703 
 704 
 705     @Benchmark
 706     public Object notEqual() {
 707         short[] a = fa.apply(size);
 708         short[] b = fb.apply(size);
 709         boolean[] ms = fm.apply(size);
 710         VectorMask<Short> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 711 
 712         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 713             for (int i = 0; i < a.length; i += SPECIES.length()) {
 714                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 715                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 716                 VectorMask<Short> mv = av.notEqual(bv);
 717 
 718                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 719             }
 720         }
 721         return m;
 722     }
 723 
 724 
 725     @Benchmark
 726     public Object lessThanEq() {
 727         short[] a = fa.apply(size);
 728         short[] b = fb.apply(size);
 729         boolean[] ms = fm.apply(size);
 730         VectorMask<Short> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 731 
 732         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 733             for (int i = 0; i < a.length; i += SPECIES.length()) {
 734                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 735                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 736                 VectorMask<Short> mv = av.lessThanEq(bv);
 737 
 738                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 739             }
 740         }
 741         return m;
 742     }
 743 
 744 
 745     @Benchmark
 746     public Object greaterThanEq() {
 747         short[] a = fa.apply(size);
 748         short[] b = fb.apply(size);
 749         boolean[] ms = fm.apply(size);
 750         VectorMask<Short> m = VectorMask.maskFromArray(SPECIES, ms, 0);
 751 
 752         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 753             for (int i = 0; i < a.length; i += SPECIES.length()) {
 754                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 755                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 756                 VectorMask<Short> mv = av.greaterThanEq(bv);
 757 
 758                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 759             }
 760         }
 761         return m;
 762     }
 763 
 764 
 765     @Benchmark
 766     public void blend(Blackhole bh) {
 767         short[] a = fa.apply(SPECIES.length());
 768         short[] b = fb.apply(SPECIES.length());
 769         short[] r = fr.apply(SPECIES.length());
 770         boolean[] mask = fm.apply(SPECIES.length());
 771         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 772 
 773         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 774             for (int i = 0; i < a.length; i += SPECIES.length()) {
 775                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 776                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 777                 av.blend(bv, vmask).intoArray(r, i);
 778             }
 779         }
 780 
 781         bh.consume(r);
 782     }
 783 
 784     @Benchmark
 785     public void rearrange(Blackhole bh) {
 786         short[] a = fa.apply(SPECIES.length());
 787         int[] order = fs.apply(a.length, SPECIES.length());
 788         short[] r = fr.apply(SPECIES.length());
 789 
 790         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 791             for (int i = 0; i < a.length; i += SPECIES.length()) {
 792                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 793                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
 794             }
 795         }
 796 
 797         bh.consume(r);
 798     }
 799 
 800     @Benchmark
 801     public void extract(Blackhole bh) {
 802         short[] a = fa.apply(SPECIES.length());
 803         short[] r = fr.apply(SPECIES.length());
 804 
 805         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 806             for (int i = 0; i < a.length; i += SPECIES.length()) {
 807                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 808                 int num_lanes = SPECIES.length();
 809                 // Manually unroll because full unroll happens after intrinsification.
 810                 // Unroll is needed because get intrinsic requires for index to be a known constant.
 811                 if (num_lanes == 1) {
 812                     r[i]=av.get(0);
 813                 } else if (num_lanes == 2) {


 976     @Benchmark
 977     public void neg(Blackhole bh) {
 978         short[] a = fa.apply(SPECIES.length());
 979         short[] r = fr.apply(SPECIES.length());
 980 
 981         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 982             for (int i = 0; i < a.length; i += SPECIES.length()) {
 983                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 984                 av.neg().intoArray(r, i);
 985             }
 986         }
 987 
 988         bh.consume(r);
 989     }
 990 
 991     @Benchmark
 992     public void negMasked(Blackhole bh) {
 993         short[] a = fa.apply(SPECIES.length());
 994         short[] r = fr.apply(SPECIES.length());
 995         boolean[] mask = fm.apply(SPECIES.length());
 996         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 997 
 998         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 999             for (int i = 0; i < a.length; i += SPECIES.length()) {
1000                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1001                 av.neg(vmask).intoArray(r, i);
1002             }
1003         }
1004 
1005         bh.consume(r);
1006     }
1007 
1008     @Benchmark
1009     public void abs(Blackhole bh) {
1010         short[] a = fa.apply(SPECIES.length());
1011         short[] r = fr.apply(SPECIES.length());
1012 
1013         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1014             for (int i = 0; i < a.length; i += SPECIES.length()) {
1015                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1016                 av.abs().intoArray(r, i);
1017             }
1018         }
1019 
1020         bh.consume(r);
1021     }
1022 
1023     @Benchmark
1024     public void absMasked(Blackhole bh) {
1025         short[] a = fa.apply(SPECIES.length());
1026         short[] r = fr.apply(SPECIES.length());
1027         boolean[] mask = fm.apply(SPECIES.length());
1028         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1029 
1030         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1031             for (int i = 0; i < a.length; i += SPECIES.length()) {
1032                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1033                 av.abs(vmask).intoArray(r, i);
1034             }
1035         }
1036 
1037         bh.consume(r);
1038     }
1039 
1040 
1041     @Benchmark
1042     public void not(Blackhole bh) {
1043         short[] a = fa.apply(SPECIES.length());
1044         short[] r = fr.apply(SPECIES.length());
1045 
1046         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1047             for (int i = 0; i < a.length; i += SPECIES.length()) {
1048                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1049                 av.not().intoArray(r, i);
1050             }
1051         }
1052 
1053         bh.consume(r);
1054     }
1055 
1056 
1057 
1058     @Benchmark
1059     public void notMasked(Blackhole bh) {
1060         short[] a = fa.apply(SPECIES.length());
1061         short[] r = fr.apply(SPECIES.length());
1062         boolean[] mask = fm.apply(SPECIES.length());
1063         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1064 
1065         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1066             for (int i = 0; i < a.length; i += SPECIES.length()) {
1067                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1068                 av.not(vmask).intoArray(r, i);
1069             }
1070         }
1071 
1072         bh.consume(r);
1073     }
1074 
1075 
1076 
1077 
1078 
1079 }
1080 
< prev index next >