< prev index next >

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

Print this page
rev 55606 : 8221812: Fine-tune jmh test for vector api
Summary: To compare performance of vector api and auto vectorization, vector
api and scalar test cases are updated to keep aligned.
Reviewed-by: duke
   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have
  21  * questions.
  22  */


 582     public void min(Blackhole bh) {
 583         int[] a = fa.apply(SPECIES.length());
 584         int[] b = fb.apply(SPECIES.length());
 585         int[] r = fr.apply(SPECIES.length());
 586 
 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 590                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 591                 av.min(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         bh.consume(r);
 596     }
 597 
 598 
 599     @Benchmark
 600     public void andAll(Blackhole bh) {
 601         int[] a = fa.apply(SPECIES.length());
 602         int[] r = fr.apply(SPECIES.length());
 603         int ra = -1;
 604 
 605         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 606             for (int i = 0; i < a.length; i += SPECIES.length()) {
 607                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 608                 r[i] = av.andAll();
 609             }
 610         }
 611 
 612         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 613             ra = -1;
 614             for (int i = 0; i < a.length; i += SPECIES.length()) {
 615                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 616                 ra &= av.andAll();
 617             }
 618         }
 619 
 620         bh.consume(ra);
 621         bh.consume(r);
 622     }
 623 
 624 
 625 
 626     @Benchmark
 627     public void orAll(Blackhole bh) {
 628         int[] a = fa.apply(SPECIES.length());
 629         int[] r = fr.apply(SPECIES.length());
 630         int ra = 0;
 631 
 632         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 633             for (int i = 0; i < a.length; i += SPECIES.length()) {
 634                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 635                 r[i] = av.orAll();
 636             }
 637         }
 638 
 639         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 640             ra = 0;
 641             for (int i = 0; i < a.length; i += SPECIES.length()) {
 642                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 643                 ra |= av.orAll();
 644             }
 645         }
 646 
 647         bh.consume(ra);
 648         bh.consume(r);
 649     }
 650 
 651 
 652 
 653     @Benchmark
 654     public void xorAll(Blackhole bh) {
 655         int[] a = fa.apply(SPECIES.length());
 656         int[] r = fr.apply(SPECIES.length());
 657         int ra = 0;
 658 
 659         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 660             for (int i = 0; i < a.length; i += SPECIES.length()) {
 661                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 662                 r[i] = av.xorAll();
 663             }
 664         }
 665 
 666         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 667             ra = 0;
 668             for (int i = 0; i < a.length; i += SPECIES.length()) {
 669                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 670                 ra ^= av.xorAll();
 671             }
 672         }
 673 
 674         bh.consume(ra);
 675         bh.consume(r);
 676     }
 677 
 678 
 679     @Benchmark
 680     public void addAll(Blackhole bh) {
 681         int[] a = fa.apply(SPECIES.length());
 682         int[] r = fr.apply(SPECIES.length());
 683         int ra = 0;
 684 
 685         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 686             for (int i = 0; i < a.length; i += SPECIES.length()) {
 687                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 688                 r[i] = av.addAll();
 689             }
 690         }
 691 
 692         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 693             ra = 0;
 694             for (int i = 0; i < a.length; i += SPECIES.length()) {
 695                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 696                 ra += av.addAll();
 697             }
 698         }
 699 
 700         bh.consume(ra);
 701         bh.consume(r);
 702     }
 703 
 704     @Benchmark
 705     public void mulAll(Blackhole bh) {
 706         int[] a = fa.apply(SPECIES.length());
 707         int[] r = fr.apply(SPECIES.length());
 708         int ra = 1;
 709 
 710         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 711             for (int i = 0; i < a.length; i += SPECIES.length()) {
 712                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 713                 r[i] = av.mulAll();
 714             }
 715         }
 716 
 717         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 718             ra = 1;
 719             for (int i = 0; i < a.length; i += SPECIES.length()) {
 720                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 721                 ra *= av.mulAll();
 722             }
 723         }
 724 
 725         bh.consume(ra);
 726         bh.consume(r);
 727     }
 728 
 729     @Benchmark
 730     public void minAll(Blackhole bh) {
 731         int[] a = fa.apply(SPECIES.length());
 732         int[] r = fr.apply(SPECIES.length());
 733         int ra = Integer.MAX_VALUE;
 734 
 735         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 736             for (int i = 0; i < a.length; i += SPECIES.length()) {
 737                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 738                 r[i] = av.minAll();
 739             }
 740         }
 741 
 742         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 743             ra = Integer.MAX_VALUE;
 744             for (int i = 0; i < a.length; i += SPECIES.length()) {
 745                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 746                 ra = (int)Math.min(ra, av.minAll());
 747             }
 748         }
 749 
 750         bh.consume(ra);
 751         bh.consume(r);
 752     }
 753 
 754     @Benchmark
 755     public void maxAll(Blackhole bh) {
 756         int[] a = fa.apply(SPECIES.length());
 757         int[] r = fr.apply(SPECIES.length());
 758         int ra = Integer.MIN_VALUE;
 759 
 760         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 761             for (int i = 0; i < a.length; i += SPECIES.length()) {
 762                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 763                 r[i] = av.maxAll();
 764             }
 765         }
 766 
 767         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 768             ra = Integer.MIN_VALUE;
 769             for (int i = 0; i < a.length; i += SPECIES.length()) {
 770                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 771                 ra = (int)Math.max(ra, av.maxAll());
 772             }
 773         }
 774 
 775         bh.consume(ra);
 776         bh.consume(r);
 777     }
 778 
 779 
 780     @Benchmark
 781     public void anyTrue(Blackhole bh) {
 782         boolean[] mask = fm.apply(SPECIES.length());
 783         boolean[] r = fmr.apply(SPECIES.length());
 784 
 785         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 786             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 787                 Vector.Mask<Integer> vmask = IntVector.maskFromArray(SPECIES, mask, i);
 788                 r[i] = vmask.anyTrue();
 789             }
 790         }
 791 
 792         bh.consume(r);
 793     }
 794 
 795 
 796 


   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have
  21  * questions.
  22  */


 582     public void min(Blackhole bh) {
 583         int[] a = fa.apply(SPECIES.length());
 584         int[] b = fb.apply(SPECIES.length());
 585         int[] r = fr.apply(SPECIES.length());
 586 
 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 590                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 591                 av.min(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         bh.consume(r);
 596     }
 597 
 598 
 599     @Benchmark
 600     public void andAll(Blackhole bh) {
 601         int[] a = fa.apply(SPECIES.length());

 602         int ra = -1;
 603 
 604         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 605             ra = -1;
 606             for (int i = 0; i < a.length; i += SPECIES.length()) {
 607                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 608                 ra &= av.andAll();
 609             }
 610         }

 611         bh.consume(ra);

 612     }
 613 
 614 
 615 
 616     @Benchmark
 617     public void orAll(Blackhole bh) {
 618         int[] a = fa.apply(SPECIES.length());

 619         int ra = 0;
 620 
 621         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 622             ra = 0;
 623             for (int i = 0; i < a.length; i += SPECIES.length()) {
 624                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 625                 ra |= av.orAll();
 626             }
 627         }

 628         bh.consume(ra);

 629     }
 630 
 631 
 632 
 633     @Benchmark
 634     public void xorAll(Blackhole bh) {
 635         int[] a = fa.apply(SPECIES.length());

 636         int ra = 0;
 637 
 638         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 639             ra = 0;
 640             for (int i = 0; i < a.length; i += SPECIES.length()) {
 641                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 642                 ra ^= av.xorAll();
 643             }
 644         }

 645         bh.consume(ra);

 646     }
 647 
 648 
 649     @Benchmark
 650     public void addAll(Blackhole bh) {
 651         int[] a = fa.apply(SPECIES.length());

 652         int ra = 0;
 653 
 654         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 655             ra = 0;
 656             for (int i = 0; i < a.length; i += SPECIES.length()) {
 657                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 658                 ra += av.addAll();
 659             }
 660         }

 661         bh.consume(ra);

 662     }
 663 
 664     @Benchmark
 665     public void mulAll(Blackhole bh) {
 666         int[] a = fa.apply(SPECIES.length());

 667         int ra = 1;
 668 
 669         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 670             ra = 1;
 671             for (int i = 0; i < a.length; i += SPECIES.length()) {
 672                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 673                 ra *= av.mulAll();
 674             }
 675         }

 676         bh.consume(ra);

 677     }
 678 
 679     @Benchmark
 680     public void minAll(Blackhole bh) {
 681         int[] a = fa.apply(SPECIES.length());

 682         int ra = Integer.MAX_VALUE;
 683 
 684         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 685             ra = Integer.MAX_VALUE;
 686             for (int i = 0; i < a.length; i += SPECIES.length()) {
 687                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 688                 ra = (int)Math.min(ra, av.minAll());
 689             }
 690         }

 691         bh.consume(ra);

 692     }
 693 
 694     @Benchmark
 695     public void maxAll(Blackhole bh) {
 696         int[] a = fa.apply(SPECIES.length());

 697         int ra = Integer.MIN_VALUE;
 698 
 699         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 700             ra = Integer.MIN_VALUE;
 701             for (int i = 0; i < a.length; i += SPECIES.length()) {
 702                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 703                 ra = (int)Math.max(ra, av.maxAll());
 704             }
 705         }

 706         bh.consume(ra);

 707     }
 708 
 709 
 710     @Benchmark
 711     public void anyTrue(Blackhole bh) {
 712         boolean[] mask = fm.apply(SPECIES.length());
 713         boolean[] r = fmr.apply(SPECIES.length());
 714 
 715         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 716             for (int i = 0; i < mask.length; i += SPECIES.length()) {
 717                 Vector.Mask<Integer> vmask = IntVector.maskFromArray(SPECIES, mask, i);
 718                 r[i] = vmask.anyTrue();
 719             }
 720         }
 721 
 722         bh.consume(r);
 723     }
 724 
 725 
 726 


< prev index next >