< prev index next >

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

Print this page
rev 55894 : 8222897: [vector] Renaming of shift, rotate operations. Few other api changes.
Summary: Renaming of shift, rotate operations. Few other api changes.
Reviewed-by: jrose, briangoetz


   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.ByteVector;
  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 Byte128Vector extends AbstractVectorBenchmark {
  46     static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;


 302         byte[] b = fb.apply(SPECIES.length());
 303         byte[] r = fr.apply(SPECIES.length());
 304         boolean[] mask = fm.apply(SPECIES.length());
 305         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 310                 ByteVector bv = ByteVector.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 
 326 
 327 
 328 
 329 
 330 
 331 
 332     @Benchmark
 333     public void aShiftRShift(Blackhole bh) {
 334         byte[] a = fa.apply(SPECIES.length());
 335         byte[] b = fb.apply(SPECIES.length());
 336         byte[] r = fr.apply(SPECIES.length());
 337 
 338         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 339             for (int i = 0; i < a.length; i += SPECIES.length()) {
 340                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 341                 av.aShiftR((int)b[i]).intoArray(r, i);

 342             }
 343         }
 344 
 345         bh.consume(r);
 346     }
 347 
 348 
 349 
 350     @Benchmark
 351     public void aShiftRMaskedShift(Blackhole bh) {
 352         byte[] a = fa.apply(SPECIES.length());
 353         byte[] b = fb.apply(SPECIES.length());
 354         byte[] r = fr.apply(SPECIES.length());
 355         boolean[] mask = fm.apply(SPECIES.length());
 356         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 357 
 358         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 359             for (int i = 0; i < a.length; i += SPECIES.length()) {
 360                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 361                 av.aShiftR((int)b[i], vmask).intoArray(r, i);

 362             }
 363         }
 364 
 365         bh.consume(r);
 366     }
 367 
 368 
 369 




 370     @Benchmark
 371     public void shiftLShift(Blackhole bh) {
 372         byte[] a = fa.apply(SPECIES.length());
 373         byte[] b = fb.apply(SPECIES.length());
 374         byte[] r = fr.apply(SPECIES.length());
 375 
 376         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 377             for (int i = 0; i < a.length; i += SPECIES.length()) {
 378                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 379                 av.shiftL((int)b[i]).intoArray(r, i);
 380             }
 381         }
 382 
 383         bh.consume(r);
 384     }
 385 
 386 
 387 
 388     @Benchmark
 389     public void shiftLMaskedShift(Blackhole bh) {
 390         byte[] a = fa.apply(SPECIES.length());
 391         byte[] b = fb.apply(SPECIES.length());
 392         byte[] r = fr.apply(SPECIES.length());
 393         boolean[] mask = fm.apply(SPECIES.length());
 394         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 395 
 396         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 397             for (int i = 0; i < a.length; i += SPECIES.length()) {
 398                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 399                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 400             }
 401         }
 402 
 403         bh.consume(r);
 404     }
 405 
 406 
 407 




 408     @Benchmark
 409     public void shiftRShift(Blackhole bh) {
 410         byte[] a = fa.apply(SPECIES.length());
 411         byte[] b = fb.apply(SPECIES.length());
 412         byte[] r = fr.apply(SPECIES.length());
 413 
 414         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 415             for (int i = 0; i < a.length; i += SPECIES.length()) {
 416                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 417                 av.shiftR((int)b[i]).intoArray(r, i);
 418             }
 419         }
 420 
 421         bh.consume(r);
 422     }
 423 
 424 
 425 
 426     @Benchmark
 427     public void shiftRMaskedShift(Blackhole bh) {
 428         byte[] a = fa.apply(SPECIES.length());
 429         byte[] b = fb.apply(SPECIES.length());
 430         byte[] r = fr.apply(SPECIES.length());
 431         boolean[] mask = fm.apply(SPECIES.length());
 432         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 433 
 434         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 435             for (int i = 0; i < a.length; i += SPECIES.length()) {
 436                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 437                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 438             }
 439         }
 440 
 441         bh.consume(r);
 442     }
 443 
 444 
 445 
 446 
 447 
 448 
 449 






































 450 
 451     @Benchmark
 452     public void max(Blackhole bh) {
 453         byte[] a = fa.apply(SPECIES.length());
 454         byte[] b = fb.apply(SPECIES.length());
 455         byte[] 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()) {
 459                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 460                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 461                 av.max(bv).intoArray(r, i);
 462             }
 463         }
 464 
 465         bh.consume(r);
 466     }
 467 
 468     @Benchmark
 469     public void min(Blackhole bh) {
 470         byte[] a = fa.apply(SPECIES.length());
 471         byte[] b = fb.apply(SPECIES.length());
 472         byte[] r = fr.apply(SPECIES.length());
 473 
 474         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 475             for (int i = 0; i < a.length; i += SPECIES.length()) {
 476                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 477                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 478                 av.min(bv).intoArray(r, i);
 479             }
 480         }
 481 
 482         bh.consume(r);
 483     }
 484 
 485 
 486     @Benchmark
 487     public void andAll(Blackhole bh) {
 488         byte[] a = fa.apply(SPECIES.length());
 489         byte ra = -1;
 490 
 491         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 492             ra = -1;
 493             for (int i = 0; i < a.length; i += SPECIES.length()) {
 494                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 495                 ra &= av.andAll();
 496             }
 497         }
 498         bh.consume(ra);
 499     }
 500 
 501 
 502 
 503     @Benchmark
 504     public void orAll(Blackhole bh) {
 505         byte[] a = fa.apply(SPECIES.length());
 506         byte ra = 0;
 507 
 508         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 509             ra = 0;
 510             for (int i = 0; i < a.length; i += SPECIES.length()) {
 511                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 512                 ra |= av.orAll();
 513             }
 514         }
 515         bh.consume(ra);
 516     }
 517 
 518 
 519 
 520     @Benchmark
 521     public void xorAll(Blackhole bh) {
 522         byte[] a = fa.apply(SPECIES.length());
 523         byte ra = 0;
 524 
 525         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 526             ra = 0;
 527             for (int i = 0; i < a.length; i += SPECIES.length()) {
 528                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 529                 ra ^= av.xorAll();
 530             }
 531         }
 532         bh.consume(ra);
 533     }
 534 
 535 
 536     @Benchmark
 537     public void addAll(Blackhole bh) {
 538         byte[] a = fa.apply(SPECIES.length());
 539         byte ra = 0;
 540 
 541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 542             ra = 0;
 543             for (int i = 0; i < a.length; i += SPECIES.length()) {
 544                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 545                 ra += av.addAll();
 546             }
 547         }
 548         bh.consume(ra);
 549     }
 550 
 551     @Benchmark
 552     public void mulAll(Blackhole bh) {
 553         byte[] a = fa.apply(SPECIES.length());
 554         byte ra = 1;
 555 
 556         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 557             ra = 1;
 558             for (int i = 0; i < a.length; i += SPECIES.length()) {
 559                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 560                 ra *= av.mulAll();
 561             }
 562         }
 563         bh.consume(ra);
 564     }
 565 
 566     @Benchmark
 567     public void minAll(Blackhole bh) {
 568         byte[] a = fa.apply(SPECIES.length());
 569         byte ra = Byte.MAX_VALUE;
 570 
 571         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 572             ra = Byte.MAX_VALUE;
 573             for (int i = 0; i < a.length; i += SPECIES.length()) {
 574                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 575                 ra = (byte)Math.min(ra, av.minAll());
 576             }
 577         }
 578         bh.consume(ra);
 579     }
 580 
 581     @Benchmark
 582     public void maxAll(Blackhole bh) {
 583         byte[] a = fa.apply(SPECIES.length());
 584         byte ra = Byte.MIN_VALUE;
 585 
 586         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 587             ra = Byte.MIN_VALUE;
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 590                 ra = (byte)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<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
 605                 r[i] = vmask.anyTrue();
 606             }
 607         }
 608 
 609         bh.consume(r);
 610     }


 630     @Benchmark
 631     public void with(Blackhole bh) {
 632         byte[] a = fa.apply(SPECIES.length());
 633         byte[] 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 638                 av.with(0, (byte)4).intoArray(r, i);
 639             }
 640         }
 641 
 642         bh.consume(r);
 643     }
 644 
 645     @Benchmark
 646     public Object lessThan() {
 647         byte[] a = fa.apply(size);
 648         byte[] b = fb.apply(size);
 649         boolean[] ms = fm.apply(size);
 650         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 655                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 656                 VectorMask<Byte> 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         byte[] a = fa.apply(size);
 668         byte[] b = fb.apply(size);
 669         boolean[] ms = fm.apply(size);
 670         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 675                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 676                 VectorMask<Byte> 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         byte[] a = fa.apply(size);
 688         byte[] b = fb.apply(size);
 689         boolean[] ms = fm.apply(size);
 690         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 695                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 696                 VectorMask<Byte> 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         byte[] a = fa.apply(size);
 708         byte[] b = fb.apply(size);
 709         boolean[] ms = fm.apply(size);
 710         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 715                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 716                 VectorMask<Byte> 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         byte[] a = fa.apply(size);
 728         byte[] b = fb.apply(size);
 729         boolean[] ms = fm.apply(size);
 730         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 735                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 736                 VectorMask<Byte> 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         byte[] a = fa.apply(size);
 748         byte[] b = fb.apply(size);
 749         boolean[] ms = fm.apply(size);
 750         VectorMask<Byte> 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                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 755                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 756                 VectorMask<Byte> 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         byte[] a = fa.apply(SPECIES.length());
 768         byte[] b = fb.apply(SPECIES.length());
 769         byte[] r = fr.apply(SPECIES.length());
 770         boolean[] mask = fm.apply(SPECIES.length());




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have
  21  * questions.
  22  */
  23 
  24 package benchmark.jdk.incubator.vector;
  25 
  26 import jdk.incubator.vector.Vector;
  27 import jdk.incubator.vector.VectorMask;
  28 import jdk.incubator.vector.VectorShape;
  29 import jdk.incubator.vector.VectorSpecies;
  30 import jdk.incubator.vector.VectorShuffle;
  31 import jdk.incubator.vector.ByteVector;
  32 
  33 import java.util.concurrent.TimeUnit;
  34 import java.util.function.BiFunction;
  35 import java.util.function.IntFunction;
  36 
  37 import org.openjdk.jmh.annotations.*;
  38 import org.openjdk.jmh.infra.Blackhole;
  39 
  40 @BenchmarkMode(Mode.Throughput)
  41 @OutputTimeUnit(TimeUnit.MILLISECONDS)
  42 @State(Scope.Benchmark)
  43 @Warmup(iterations = 3, time = 1)
  44 @Measurement(iterations = 5, time = 1)
  45 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
  46 public class Byte128Vector extends AbstractVectorBenchmark {
  47     static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;


 303         byte[] b = fb.apply(SPECIES.length());
 304         byte[] r = fr.apply(SPECIES.length());
 305         boolean[] mask = fm.apply(SPECIES.length());
 306         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 307 
 308         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 309             for (int i = 0; i < a.length; i += SPECIES.length()) {
 310                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 311                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 312                 av.xor(bv, vmask).intoArray(r, i);
 313             }
 314         }
 315 
 316         bh.consume(r);
 317     }
 318 
 319 
 320 
 321 
 322 
 323     @Benchmark
 324     public void shiftLeft(Blackhole bh) {
 325         byte[] a = fa.apply(SPECIES.length());
 326         byte[] b = fb.apply(SPECIES.length());
 327         byte[] r = fr.apply(SPECIES.length());
 328 
 329         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 330             for (int i = 0; i < a.length; i += SPECIES.length()) {
 331                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 332                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 333                 av.shiftLeft(bv).intoArray(r, i);
 334             }
 335         }
 336 
 337         bh.consume(r);
 338     }
 339 
 340 
 341 
 342     @Benchmark
 343     public void shiftLeftMasked(Blackhole bh) {
 344         byte[] a = fa.apply(SPECIES.length());
 345         byte[] b = fb.apply(SPECIES.length());
 346         byte[] r = fr.apply(SPECIES.length());
 347         boolean[] mask = fm.apply(SPECIES.length());
 348         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 349 
 350         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 351             for (int i = 0; i < a.length; i += SPECIES.length()) {
 352                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 353                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 354                 av.shiftLeft(bv, vmask).intoArray(r, i);
 355             }
 356         }
 357 
 358         bh.consume(r);
 359     }
 360 
 361 
 362 
 363 
 364 
 365 
 366 
 367     @Benchmark
 368     public void shiftRight(Blackhole bh) {
 369         byte[] a = fa.apply(SPECIES.length());
 370         byte[] b = fb.apply(SPECIES.length());
 371         byte[] r = fr.apply(SPECIES.length());
 372 
 373         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 374             for (int i = 0; i < a.length; i += SPECIES.length()) {
 375                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 376                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 377                 av.shiftRight(bv).intoArray(r, i);
 378             }
 379         }
 380 
 381         bh.consume(r);
 382     }
 383 
 384 
 385 
 386     @Benchmark
 387     public void shiftRightMasked(Blackhole bh) {
 388         byte[] a = fa.apply(SPECIES.length());
 389         byte[] b = fb.apply(SPECIES.length());
 390         byte[] r = fr.apply(SPECIES.length());
 391         boolean[] mask = fm.apply(SPECIES.length());
 392         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 393 
 394         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 395             for (int i = 0; i < a.length; i += SPECIES.length()) {
 396                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 397                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 398                 av.shiftRight(bv, vmask).intoArray(r, i);
 399             }
 400         }
 401 
 402         bh.consume(r);
 403     }
 404 
 405 
 406 
 407 
 408 
 409 
 410 
 411     @Benchmark
 412     public void shiftArithmeticRight(Blackhole bh) {
 413         byte[] a = fa.apply(SPECIES.length());
 414         byte[] b = fb.apply(SPECIES.length());
 415         byte[] r = fr.apply(SPECIES.length());
 416 
 417         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 418             for (int i = 0; i < a.length; i += SPECIES.length()) {
 419                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 420                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 421                 av.shiftArithmeticRight(bv).intoArray(r, i);
 422             }
 423         }
 424 
 425         bh.consume(r);
 426     }
 427 
 428 
 429 
 430     @Benchmark
 431     public void shiftArithmeticRightMasked(Blackhole bh) {
 432         byte[] a = fa.apply(SPECIES.length());
 433         byte[] b = fb.apply(SPECIES.length());
 434         byte[] r = fr.apply(SPECIES.length());
 435         boolean[] mask = fm.apply(SPECIES.length());
 436         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 437 
 438         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 439             for (int i = 0; i < a.length; i += SPECIES.length()) {
 440                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 441                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 442                 av.shiftArithmeticRight(bv, vmask).intoArray(r, i);
 443             }
 444         }
 445 
 446         bh.consume(r);
 447     }
 448 
 449 
 450 
 451 
 452 
 453 
 454 
 455     @Benchmark
 456     public void shiftLeftShift(Blackhole bh) {
 457         byte[] a = fa.apply(SPECIES.length());
 458         byte[] b = fb.apply(SPECIES.length());
 459         byte[] r = fr.apply(SPECIES.length());
 460 
 461         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 462             for (int i = 0; i < a.length; i += SPECIES.length()) {
 463                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 464                 av.shiftLeft((int)b[i]).intoArray(r, i);
 465             }
 466         }
 467 
 468         bh.consume(r);
 469     }
 470 
 471 
 472 
 473     @Benchmark
 474     public void shiftLeftMaskedShift(Blackhole bh) {
 475         byte[] a = fa.apply(SPECIES.length());
 476         byte[] b = fb.apply(SPECIES.length());
 477         byte[] r = fr.apply(SPECIES.length());
 478         boolean[] mask = fm.apply(SPECIES.length());
 479         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 480 
 481         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 482             for (int i = 0; i < a.length; i += SPECIES.length()) {
 483                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 484                 av.shiftLeft((int)b[i], vmask).intoArray(r, i);
 485             }
 486         }
 487 
 488         bh.consume(r);
 489     }
 490 
 491 
 492 
 493 
 494 
 495 
 496 
 497     @Benchmark
 498     public void shiftRightShift(Blackhole bh) {
 499         byte[] a = fa.apply(SPECIES.length());
 500         byte[] b = fb.apply(SPECIES.length());
 501         byte[] r = fr.apply(SPECIES.length());
 502 
 503         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 504             for (int i = 0; i < a.length; i += SPECIES.length()) {
 505                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 506                 av.shiftRight((int)b[i]).intoArray(r, i);
 507             }
 508         }
 509 
 510         bh.consume(r);
 511     }
 512 
 513 
 514 
 515     @Benchmark
 516     public void shiftRightMaskedShift(Blackhole bh) {
 517         byte[] a = fa.apply(SPECIES.length());
 518         byte[] b = fb.apply(SPECIES.length());
 519         byte[] r = fr.apply(SPECIES.length());
 520         boolean[] mask = fm.apply(SPECIES.length());
 521         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 522 
 523         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 524             for (int i = 0; i < a.length; i += SPECIES.length()) {
 525                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 526                 av.shiftRight((int)b[i], vmask).intoArray(r, i);
 527             }
 528         }
 529 
 530         bh.consume(r);
 531     }
 532 
 533 
 534 
 535 
 536 
 537 
 538 
 539     @Benchmark
 540     public void shiftArithmeticRightShift(Blackhole bh) {
 541         byte[] a = fa.apply(SPECIES.length());
 542         byte[] b = fb.apply(SPECIES.length());
 543         byte[] r = fr.apply(SPECIES.length());
 544 
 545         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 546             for (int i = 0; i < a.length; i += SPECIES.length()) {
 547                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 548                 av.shiftArithmeticRight((int)b[i]).intoArray(r, i);
 549             }
 550         }
 551 
 552         bh.consume(r);
 553     }
 554 
 555 
 556 
 557     @Benchmark
 558     public void shiftArithmeticRightMaskedShift(Blackhole bh) {
 559         byte[] a = fa.apply(SPECIES.length());
 560         byte[] b = fb.apply(SPECIES.length());
 561         byte[] r = fr.apply(SPECIES.length());
 562         boolean[] mask = fm.apply(SPECIES.length());
 563         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 564 
 565         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 566             for (int i = 0; i < a.length; i += SPECIES.length()) {
 567                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 568                 av.shiftArithmeticRight((int)b[i], vmask).intoArray(r, i);
 569             }
 570         }
 571 
 572         bh.consume(r);
 573     }
 574 
 575 
 576 
 577 
 578     @Benchmark
 579     public void max(Blackhole bh) {
 580         byte[] a = fa.apply(SPECIES.length());
 581         byte[] b = fb.apply(SPECIES.length());
 582         byte[] r = fr.apply(SPECIES.length());
 583 
 584         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 585             for (int i = 0; i < a.length; i += SPECIES.length()) {
 586                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 587                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 588                 av.max(bv).intoArray(r, i);
 589             }
 590         }
 591 
 592         bh.consume(r);
 593     }
 594 
 595     @Benchmark
 596     public void min(Blackhole bh) {
 597         byte[] a = fa.apply(SPECIES.length());
 598         byte[] b = fb.apply(SPECIES.length());
 599         byte[] r = fr.apply(SPECIES.length());
 600 
 601         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 602             for (int i = 0; i < a.length; i += SPECIES.length()) {
 603                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 604                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 605                 av.min(bv).intoArray(r, i);
 606             }
 607         }
 608 
 609         bh.consume(r);
 610     }
 611 
 612 
 613     @Benchmark
 614     public void andLanes(Blackhole bh) {
 615         byte[] a = fa.apply(SPECIES.length());
 616         byte ra = -1;
 617 
 618         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 619             ra = -1;
 620             for (int i = 0; i < a.length; i += SPECIES.length()) {
 621                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 622                 ra &= av.andLanes();
 623             }
 624         }
 625         bh.consume(ra);
 626     }
 627 
 628 
 629 
 630     @Benchmark
 631     public void orLanes(Blackhole bh) {
 632         byte[] a = fa.apply(SPECIES.length());
 633         byte ra = 0;
 634 
 635         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 636             ra = 0;
 637             for (int i = 0; i < a.length; i += SPECIES.length()) {
 638                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 639                 ra |= av.orLanes();
 640             }
 641         }
 642         bh.consume(ra);
 643     }
 644 
 645 
 646 
 647     @Benchmark
 648     public void xorLanes(Blackhole bh) {
 649         byte[] a = fa.apply(SPECIES.length());
 650         byte ra = 0;
 651 
 652         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 653             ra = 0;
 654             for (int i = 0; i < a.length; i += SPECIES.length()) {
 655                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 656                 ra ^= av.xorLanes();
 657             }
 658         }
 659         bh.consume(ra);
 660     }
 661 
 662 
 663     @Benchmark
 664     public void addLanes(Blackhole bh) {
 665         byte[] a = fa.apply(SPECIES.length());
 666         byte ra = 0;
 667 
 668         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 669             ra = 0;
 670             for (int i = 0; i < a.length; i += SPECIES.length()) {
 671                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 672                 ra += av.addLanes();
 673             }
 674         }
 675         bh.consume(ra);
 676     }
 677 
 678     @Benchmark
 679     public void mulLanes(Blackhole bh) {
 680         byte[] a = fa.apply(SPECIES.length());
 681         byte ra = 1;
 682 
 683         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 684             ra = 1;
 685             for (int i = 0; i < a.length; i += SPECIES.length()) {
 686                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 687                 ra *= av.mulLanes();
 688             }
 689         }
 690         bh.consume(ra);
 691     }
 692 
 693     @Benchmark
 694     public void minLanes(Blackhole bh) {
 695         byte[] a = fa.apply(SPECIES.length());
 696         byte ra = Byte.MAX_VALUE;
 697 
 698         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 699             ra = Byte.MAX_VALUE;
 700             for (int i = 0; i < a.length; i += SPECIES.length()) {
 701                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 702                 ra = (byte)Math.min(ra, av.minLanes());
 703             }
 704         }
 705         bh.consume(ra);
 706     }
 707 
 708     @Benchmark
 709     public void maxLanes(Blackhole bh) {
 710         byte[] a = fa.apply(SPECIES.length());
 711         byte ra = Byte.MIN_VALUE;
 712 
 713         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 714             ra = Byte.MIN_VALUE;
 715             for (int i = 0; i < a.length; i += SPECIES.length()) {
 716                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 717                 ra = (byte)Math.max(ra, av.maxLanes());
 718             }
 719         }
 720         bh.consume(ra);
 721     }
 722 
 723 
 724     @Benchmark
 725     public void anyTrue(Blackhole bh) {
 726         boolean[] mask = fm.apply(SPECIES.length());
 727         boolean[] r = fmr.apply(SPECIES.length());
 728 
 729         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 730             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 731                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
 732                 r[i] = vmask.anyTrue();
 733             }
 734         }
 735 
 736         bh.consume(r);
 737     }


 757     @Benchmark
 758     public void with(Blackhole bh) {
 759         byte[] a = fa.apply(SPECIES.length());
 760         byte[] r = fr.apply(SPECIES.length());
 761 
 762         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 763             for (int i = 0; i < a.length; i += SPECIES.length()) {
 764                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 765                 av.with(0, (byte)4).intoArray(r, i);
 766             }
 767         }
 768 
 769         bh.consume(r);
 770     }
 771 
 772     @Benchmark
 773     public Object lessThan() {
 774         byte[] a = fa.apply(size);
 775         byte[] b = fb.apply(size);
 776         boolean[] ms = fm.apply(size);
 777         VectorMask<Byte> m = VectorMask.fromArray(SPECIES, ms, 0);
 778 
 779         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 780             for (int i = 0; i < a.length; i += SPECIES.length()) {
 781                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 782                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 783                 VectorMask<Byte> mv = av.lessThan(bv);
 784 
 785                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 786             }
 787         }
 788         return m;
 789     }
 790 
 791 
 792     @Benchmark
 793     public Object greaterThan() {
 794         byte[] a = fa.apply(size);
 795         byte[] b = fb.apply(size);
 796         boolean[] ms = fm.apply(size);
 797         VectorMask<Byte> m = VectorMask.fromArray(SPECIES, ms, 0);
 798 
 799         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 800             for (int i = 0; i < a.length; i += SPECIES.length()) {
 801                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 802                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 803                 VectorMask<Byte> mv = av.greaterThan(bv);
 804 
 805                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 806             }
 807         }
 808         return m;
 809     }
 810 
 811 
 812     @Benchmark
 813     public Object equal() {
 814         byte[] a = fa.apply(size);
 815         byte[] b = fb.apply(size);
 816         boolean[] ms = fm.apply(size);
 817         VectorMask<Byte> m = VectorMask.fromArray(SPECIES, ms, 0);
 818 
 819         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 820             for (int i = 0; i < a.length; i += SPECIES.length()) {
 821                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 822                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 823                 VectorMask<Byte> mv = av.equal(bv);
 824 
 825                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 826             }
 827         }
 828         return m;
 829     }
 830 
 831 
 832     @Benchmark
 833     public Object notEqual() {
 834         byte[] a = fa.apply(size);
 835         byte[] b = fb.apply(size);
 836         boolean[] ms = fm.apply(size);
 837         VectorMask<Byte> m = VectorMask.fromArray(SPECIES, ms, 0);
 838 
 839         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 840             for (int i = 0; i < a.length; i += SPECIES.length()) {
 841                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 842                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 843                 VectorMask<Byte> mv = av.notEqual(bv);
 844 
 845                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 846             }
 847         }
 848         return m;
 849     }
 850 
 851 
 852     @Benchmark
 853     public Object lessThanEq() {
 854         byte[] a = fa.apply(size);
 855         byte[] b = fb.apply(size);
 856         boolean[] ms = fm.apply(size);
 857         VectorMask<Byte> m = VectorMask.fromArray(SPECIES, ms, 0);
 858 
 859         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 860             for (int i = 0; i < a.length; i += SPECIES.length()) {
 861                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 862                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 863                 VectorMask<Byte> mv = av.lessThanEq(bv);
 864 
 865                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 866             }
 867         }
 868         return m;
 869     }
 870 
 871 
 872     @Benchmark
 873     public Object greaterThanEq() {
 874         byte[] a = fa.apply(size);
 875         byte[] b = fb.apply(size);
 876         boolean[] ms = fm.apply(size);
 877         VectorMask<Byte> m = VectorMask.fromArray(SPECIES, ms, 0);
 878 
 879         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 880             for (int i = 0; i < a.length; i += SPECIES.length()) {
 881                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 882                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 883                 VectorMask<Byte> mv = av.greaterThanEq(bv);
 884 
 885                 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
 886             }
 887         }
 888         return m;
 889     }
 890 
 891 
 892     @Benchmark
 893     public void blend(Blackhole bh) {
 894         byte[] a = fa.apply(SPECIES.length());
 895         byte[] b = fb.apply(SPECIES.length());
 896         byte[] r = fr.apply(SPECIES.length());
 897         boolean[] mask = fm.apply(SPECIES.length());


< prev index next >