hotspot/test/compiler/loopopts/superword/ReductionPerf.java
changeset 40059 c2304140ed64
parent 36057 867e857daf84
child 41705 332239c052cc
equal deleted inserted replaced
40058:b4441f6cfe79 40059:c2304140ed64
    26  * @test
    26  * @test
    27  * @bug 8074981
    27  * @bug 8074981
    28  * @summary Add C2 x86 Superword support for scalar product reduction optimizations : int test
    28  * @summary Add C2 x86 Superword support for scalar product reduction optimizations : int test
    29  * @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64"
    29  * @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64"
    30  *
    30  *
    31  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+SuperWordReductions -XX:LoopUnrollLimit=250 -XX:CompileThresholdScaling=0.1 -XX:CompileCommand=exclude,ReductionPerf::main ReductionPerf
    31  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
    32  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-SuperWordReductions -XX:LoopUnrollLimit=250 -XX:CompileThresholdScaling=0.1 -XX:CompileCommand=exclude,ReductionPerf::main ReductionPerf
    32  *      -XX:LoopUnrollLimit=250 -XX:CompileThresholdScaling=0.1
       
    33  *      -XX:CompileCommand=exclude,compiler.loopopts.superword.ReductionPerf::main
       
    34  *      -XX:+SuperWordReductions
       
    35  *      compiler.loopopts.superword.ReductionPerf
       
    36  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
       
    37  *      -XX:LoopUnrollLimit=250 -XX:CompileThresholdScaling=0.1
       
    38  *      -XX:CompileCommand=exclude,compiler.loopopts.superword.ReductionPerf::main
       
    39  *      -XX:-SuperWordReductions
       
    40  *      compiler.loopopts.superword.ReductionPerf
    33  */
    41  */
    34 
    42 
       
    43 package compiler.loopopts.superword;
       
    44 
    35 public class ReductionPerf {
    45 public class ReductionPerf {
    36   public static void main(String[] args) throws Exception {
    46     public static void main(String[] args) throws Exception {
    37     int[] a1 = new int[8*1024];
    47         int[] a1 = new int[8 * 1024];
    38     int[] a2 = new int[8*1024];
    48         int[] a2 = new int[8 * 1024];
    39     int[] a3 = new int[8*1024];
    49         int[] a3 = new int[8 * 1024];
    40     long[] b1 = new long[8*1024];
    50         long[] b1 = new long[8 * 1024];
    41     long[] b2 = new long[8*1024];
    51         long[] b2 = new long[8 * 1024];
    42     long[] b3 = new long[8*1024];
    52         long[] b3 = new long[8 * 1024];
    43     float[] c1 = new float[8*1024];
    53         float[] c1 = new float[8 * 1024];
    44     float[] c2 = new float[8*1024];
    54         float[] c2 = new float[8 * 1024];
    45     float[] c3 = new float[8*1024];
    55         float[] c3 = new float[8 * 1024];
    46     double[] d1 = new double[8*1024];
    56         double[] d1 = new double[8 * 1024];
    47     double[] d2 = new double[8*1024];
    57         double[] d2 = new double[8 * 1024];
    48     double[] d3 = new double[8*1024];
    58         double[] d3 = new double[8 * 1024];
    49 
    59 
    50     ReductionInit(a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3);
    60         ReductionInit(a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3);
    51 
    61 
    52     int    sumIv = sumInt(a1,a2,a3);
    62         int sumIv = sumInt(a1, a2, a3);
    53     long   sumLv = sumLong(b1,b2,b3);
    63         long sumLv = sumLong(b1, b2, b3);
    54     float  sumFv = sumFloat(c1,c2,c3);
    64         float sumFv = sumFloat(c1, c2, c3);
    55     double sumDv = sumDouble(d1,d2,d3);
    65         double sumDv = sumDouble(d1, d2, d3);
    56     int    mulIv = prodInt(a1,a2,a3);
    66         int mulIv = prodInt(a1, a2, a3);
    57     long   mulLv = prodLong(b1,b2,b3);
    67         long mulLv = prodLong(b1, b2, b3);
    58     float  mulFv = prodFloat(c1,c2,c3);
    68         float mulFv = prodFloat(c1, c2, c3);
    59     double mulDv = prodDouble(d1,d2,d3);
    69         double mulDv = prodDouble(d1, d2, d3);
    60 
    70 
    61     int    sumI = 0;
    71         int sumI = 0;
    62     long   sumL = 0;
    72         long sumL = 0;
    63     float  sumF = 0.f;
    73         float sumF = 0.f;
    64     double sumD = 0.;
    74         double sumD = 0.;
    65     int    mulI = 0;
    75         int mulI = 0;
    66     long   mulL = 0;
    76         long mulL = 0;
    67     float  mulF = 0.f;
    77         float mulF = 0.f;
    68     double mulD = 0.;
    78         double mulD = 0.;
    69 
    79 
    70     System.out.println("Warmup ...");
    80         System.out.println("Warmup ...");
    71     long  start = System.currentTimeMillis();
    81         long start = System.currentTimeMillis();
    72 
    82 
    73     for(int j = 0; j < 2000; j++) {
    83         for (int j = 0; j < 2000; j++) {
    74       sumI = sumInt(a1,a2,a3);
    84             sumI = sumInt(a1, a2, a3);
    75       sumL = sumLong(b1,b2,b3);
    85             sumL = sumLong(b1, b2, b3);
    76       sumF = sumFloat(c1,c2,c3);
    86             sumF = sumFloat(c1, c2, c3);
    77       sumD = sumDouble(d1,d2,d3);
    87             sumD = sumDouble(d1, d2, d3);
    78       mulI = prodInt(a1,a2,a3);
    88             mulI = prodInt(a1, a2, a3);
    79       mulL = prodLong(b1,b2,b3);
    89             mulL = prodLong(b1, b2, b3);
    80       mulF = prodFloat(c1,c2,c3);
    90             mulF = prodFloat(c1, c2, c3);
    81       mulD = prodDouble(d1,d2,d3);
    91             mulD = prodDouble(d1, d2, d3);
    82     }
    92         }
    83 
    93 
    84     long stop = System.currentTimeMillis();
    94         long stop = System.currentTimeMillis();
    85     System.out.println(" Warmup is done in " + (stop - start) + " msec");
    95         System.out.println(" Warmup is done in " + (stop - start) + " msec");
    86 
    96 
    87     if (sumIv != sumI) {
    97         if (sumIv != sumI) {
    88       System.out.println("sum int:    " + sumIv + " != " + sumI);
    98             System.out.println("sum int:    " + sumIv + " != " + sumI);
    89     }
    99         }
    90     if (sumLv != sumL) {
   100         if (sumLv != sumL) {
    91       System.out.println("sum long:   " + sumLv + " != " + sumL);
   101             System.out.println("sum long:   " + sumLv + " != " + sumL);
    92     }
   102         }
    93     if (sumFv != sumF) {
   103         if (sumFv != sumF) {
    94       System.out.println("sum float:  " + sumFv + " != " + sumF);
   104             System.out.println("sum float:  " + sumFv + " != " + sumF);
    95     }
   105         }
    96     if (sumDv != sumD) {
   106         if (sumDv != sumD) {
    97       System.out.println("sum double: " + sumDv + " != " + sumD);
   107             System.out.println("sum double: " + sumDv + " != " + sumD);
    98     }
   108         }
    99     if (mulIv != mulI) {
   109         if (mulIv != mulI) {
   100       System.out.println("prod int:    " + mulIv + " != " + mulI);
   110             System.out.println("prod int:    " + mulIv + " != " + mulI);
   101     }
   111         }
   102     if (mulLv != mulL) {
   112         if (mulLv != mulL) {
   103       System.out.println("prod long:   " + mulLv + " != " + mulL);
   113             System.out.println("prod long:   " + mulLv + " != " + mulL);
   104     }
   114         }
   105     if (mulFv != mulF) {
   115         if (mulFv != mulF) {
   106       System.out.println("prod float:  " + mulFv + " != " + mulF);
   116             System.out.println("prod float:  " + mulFv + " != " + mulF);
   107     }
   117         }
   108     if (mulDv != mulD) {
   118         if (mulDv != mulD) {
   109       System.out.println("prod double: " + mulDv + " != " + mulD);
   119             System.out.println("prod double: " + mulDv + " != " + mulD);
   110     }
   120         }
   111 
   121 
   112     start = System.currentTimeMillis();
   122         start = System.currentTimeMillis();
   113     for (int j = 0; j < 5000; j++) {
   123         for (int j = 0; j < 5000; j++) {
   114       sumI = sumInt(a1, a2 ,a3);
   124             sumI = sumInt(a1, a2, a3);
   115     }
   125         }
   116     stop = System.currentTimeMillis();
   126         stop = System.currentTimeMillis();
   117     System.out.println("sum int:    " + (stop - start));
   127         System.out.println("sum int:    " + (stop - start));
   118 
   128 
   119     start = System.currentTimeMillis();
   129         start = System.currentTimeMillis();
   120     for (int j = 0; j < 5000; j++) {
   130         for (int j = 0; j < 5000; j++) {
   121       sumL = sumLong(b1, b2, b3);
   131             sumL = sumLong(b1, b2, b3);
   122     }
   132         }
   123     stop = System.currentTimeMillis();
   133         stop = System.currentTimeMillis();
   124     System.out.println("sum long:   " + (stop - start));
   134         System.out.println("sum long:   " + (stop - start));
   125 
   135 
   126     start = System.currentTimeMillis();
   136         start = System.currentTimeMillis();
   127     for (int j = 0; j < 5000; j++) {
   137         for (int j = 0; j < 5000; j++) {
   128       sumF = sumFloat(c1, c2, c3);
   138             sumF = sumFloat(c1, c2, c3);
   129     }
   139         }
   130     stop = System.currentTimeMillis();
   140         stop = System.currentTimeMillis();
   131     System.out.println("sum float:  " + (stop - start));
   141         System.out.println("sum float:  " + (stop - start));
   132 
   142 
   133     start = System.currentTimeMillis();
   143         start = System.currentTimeMillis();
   134     for (int j = 0; j < 5000; j++) {
   144         for (int j = 0; j < 5000; j++) {
   135       sumD = sumDouble(d1, d2, d3);
   145             sumD = sumDouble(d1, d2, d3);
   136     }
   146         }
   137     stop = System.currentTimeMillis();
   147         stop = System.currentTimeMillis();
   138     System.out.println("sum double: " + (stop - start));
   148         System.out.println("sum double: " + (stop - start));
   139 
   149 
   140     start = System.currentTimeMillis();
   150         start = System.currentTimeMillis();
   141     for (int j = 0; j < 5000; j++) {
   151         for (int j = 0; j < 5000; j++) {
   142       mulI = prodInt(a1, a2, a3);
   152             mulI = prodInt(a1, a2, a3);
   143     }
   153         }
   144     stop = System.currentTimeMillis();
   154         stop = System.currentTimeMillis();
   145     System.out.println("prod int:    " + (stop - start));
   155         System.out.println("prod int:    " + (stop - start));
   146 
   156 
   147     start = System.currentTimeMillis();
   157         start = System.currentTimeMillis();
   148     for (int j = 0; j < 5000; j++) {
   158         for (int j = 0; j < 5000; j++) {
   149       mulL = prodLong(b1, b2 ,b3);
   159             mulL = prodLong(b1, b2, b3);
   150     }
   160         }
   151     stop = System.currentTimeMillis();
   161         stop = System.currentTimeMillis();
   152     System.out.println("prod long:   " + (stop - start));
   162         System.out.println("prod long:   " + (stop - start));
   153 
   163 
   154     start = System.currentTimeMillis();
   164         start = System.currentTimeMillis();
   155     for (int j = 0; j < 5000; j++) {
   165         for (int j = 0; j < 5000; j++) {
   156       mulF = prodFloat(c1, c2, c3);
   166             mulF = prodFloat(c1, c2, c3);
   157     }
   167         }
   158     stop = System.currentTimeMillis();
   168         stop = System.currentTimeMillis();
   159     System.out.println("prod float:  " + (stop - start));
   169         System.out.println("prod float:  " + (stop - start));
   160 
   170 
   161     start = System.currentTimeMillis();
   171         start = System.currentTimeMillis();
   162     for (int j = 0; j < 5000; j++) {
   172         for (int j = 0; j < 5000; j++) {
   163       mulD = prodDouble(d1, d2, d3);
   173             mulD = prodDouble(d1, d2, d3);
   164     }
   174         }
   165     stop = System.currentTimeMillis();
   175         stop = System.currentTimeMillis();
   166     System.out.println("prod double: " + (stop - start));
   176         System.out.println("prod double: " + (stop - start));
   167 
   177 
   168   }
   178     }
   169 
   179 
   170   public static void ReductionInit(int[]    a1, int[]    a2, int[]    a3,
   180     public static void ReductionInit(int[] a1, int[] a2, int[] a3,
   171                                    long[]   b1, long[]   b2, long[]   b3,
   181                                      long[] b1, long[] b2, long[] b3,
   172                                    float[]  c1, float[]  c2, float[]  c3,
   182                                      float[] c1, float[] c2, float[] c3,
   173                                    double[] d1, double[] d2, double[] d3 ) {
   183                                      double[] d1, double[] d2, double[] d3) {
   174     for(int i = 0; i < a1.length; i++) {
   184         for(int i = 0; i < a1.length; i++) {
   175       a1[i] =          (i + 0);
   185             a1[i] =          (i + 0);
   176       a2[i] =          (i + 1);
   186             a2[i] =          (i + 1);
   177       a3[i] =          (i + 2);
   187             a3[i] =          (i + 2);
   178       b1[i] =   (long) (i + 0);
   188             b1[i] =   (long) (i + 0);
   179       b2[i] =   (long) (i + 1);
   189             b2[i] =   (long) (i + 1);
   180       b3[i] =   (long) (i + 2);
   190             b3[i] =   (long) (i + 2);
   181       c1[i] =  (float) (i + 0);
   191             c1[i] =  (float) (i + 0);
   182       c2[i] =  (float) (i + 1);
   192             c2[i] =  (float) (i + 1);
   183       c3[i] =  (float) (i + 2);
   193             c3[i] =  (float) (i + 2);
   184       d1[i] = (double) (i + 0);
   194             d1[i] = (double) (i + 0);
   185       d2[i] = (double) (i + 1);
   195             d2[i] = (double) (i + 1);
   186       d3[i] = (double) (i + 2);
   196             d3[i] = (double) (i + 2);
   187     }
   197         }
   188   }
   198     }
   189 
   199 
   190   public static int sumInt(int[] a1, int[] a2, int[] a3) {
   200     public static int sumInt(int[] a1, int[] a2, int[] a3) {
   191     int total = 0;
   201         int total = 0;
   192     for(int i = 0; i < a1.length; i++) {
   202         for (int i = 0; i < a1.length; i++) {
   193       total += (a1[i] * a2[i]) + (a1[i] * a3[i]) + (a2[i] * a3[i]);
   203             total += (a1[i] * a2[i]) + (a1[i] * a3[i]) + (a2[i] * a3[i]);
   194     }
   204         }
   195     return total;
   205         return total;
   196   }
   206     }
   197 
   207 
   198   public static long sumLong(long[] b1, long[] b2, long[] b3) {
   208     public static long sumLong(long[] b1, long[] b2, long[] b3) {
   199     long total = 0;
   209         long total = 0;
   200     for(int i = 0; i < b1.length; i++) {
   210         for (int i = 0; i < b1.length; i++) {
   201       total += (b1[i] * b2[i]) + (b1[i] * b3[i]) + (b2[i] * b3[i]);
   211             total += (b1[i] * b2[i]) + (b1[i] * b3[i]) + (b2[i] * b3[i]);
   202     }
   212         }
   203     return total;
   213         return total;
   204   }
   214     }
   205 
   215 
   206   public static float sumFloat(float[] c1, float[] c2, float[] c3) {
   216     public static float sumFloat(float[] c1, float[] c2, float[] c3) {
   207     float total = 0;
   217         float total = 0;
   208     for(int i = 0; i < c1.length; i++) {
   218         for (int i = 0; i < c1.length; i++) {
   209       total += (c1[i] * c2[i]) + (c1[i] * c3[i]) + (c2[i] * c3[i]);
   219             total += (c1[i] * c2[i]) + (c1[i] * c3[i]) + (c2[i] * c3[i]);
   210     }
   220         }
   211     return total;
   221         return total;
   212   }
   222     }
   213 
   223 
   214   public static double sumDouble(double[] d1, double[] d2, double[] d3) {
   224     public static double sumDouble(double[] d1, double[] d2, double[] d3) {
   215     double total = 0;
   225         double total = 0;
   216     for(int i = 0; i < d1.length; i++) {
   226         for (int i = 0; i < d1.length; i++) {
   217       total += (d1[i] * d2[i]) + (d1[i] * d3[i]) + (d2[i] * d3[i]);
   227             total += (d1[i] * d2[i]) + (d1[i] * d3[i]) + (d2[i] * d3[i]);
   218     }
   228         }
   219     return total;
   229         return total;
   220   }
   230     }
   221 
   231 
   222   public static int prodInt(int[] a1, int[] a2, int[] a3) {
   232     public static int prodInt(int[] a1, int[] a2, int[] a3) {
   223     int total = 1;
   233         int total = 1;
   224     for(int i = 0; i < a1.length; i++) {
   234         for (int i = 0; i < a1.length; i++) {
   225       total *= (a1[i] * a2[i]) + (a1[i] * a3[i]) + (a2[i] * a3[i]);
   235             total *= (a1[i] * a2[i]) + (a1[i] * a3[i]) + (a2[i] * a3[i]);
   226     }
   236         }
   227     return total;
   237         return total;
   228   }
   238     }
   229 
   239 
   230   public static long prodLong(long[] b1, long[] b2, long[] b3) {
   240     public static long prodLong(long[] b1, long[] b2, long[] b3) {
   231     long total = 1;
   241         long total = 1;
   232     for(int i = 0; i < b1.length; i++) {
   242         for (int i = 0; i < b1.length; i++) {
   233       total *= (b1[i] * b2[i]) + (b1[i] * b3[i]) + (b2[i] * b3[i]);
   243             total *= (b1[i] * b2[i]) + (b1[i] * b3[i]) + (b2[i] * b3[i]);
   234     }
   244         }
   235     return total;
   245         return total;
   236   }
   246     }
   237 
   247 
   238   public static float prodFloat(float[] c1, float[] c2, float[] c3) {
   248     public static float prodFloat(float[] c1, float[] c2, float[] c3) {
   239     float total = 1;
   249         float total = 1;
   240     for(int i = 0; i < c1.length; i++) {
   250         for (int i = 0; i < c1.length; i++) {
   241       total *= (c1[i] * c2[i]) + (c1[i] * c3[i]) + (c2[i] * c3[i]);
   251             total *= (c1[i] * c2[i]) + (c1[i] * c3[i]) + (c2[i] * c3[i]);
   242     }
   252         }
   243     return total;
   253         return total;
   244   }
   254     }
   245 
   255 
   246   public static double prodDouble(double[] d1, double[] d2, double[] d3) {
   256     public static double prodDouble(double[] d1, double[] d2, double[] d3) {
   247     double total = 1;
   257         double total = 1;
   248     for(int i = 0; i < d1.length; i++) {
   258         for (int i = 0; i < d1.length; i++) {
   249       total *= (d1[i] * d2[i]) + (d1[i] * d3[i]) + (d2[i] * d3[i]);
   259             total *= (d1[i] * d2[i]) + (d1[i] * d3[i]) + (d2[i] * d3[i]);
   250     }
   260         }
   251     return total;
   261         return total;
   252   }
   262     }
   253 }
   263 }