1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar product reduction optimizations : int test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
* -XX:LoopUnrollLimit=250 -XX:CompileThresholdScaling=0.1
* -XX:CompileCommand=exclude,compiler.loopopts.superword.ReductionPerf::main
* -XX:+SuperWordReductions
* compiler.loopopts.superword.ReductionPerf
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
* -XX:LoopUnrollLimit=250 -XX:CompileThresholdScaling=0.1
* -XX:CompileCommand=exclude,compiler.loopopts.superword.ReductionPerf::main
* -XX:-SuperWordReductions
* compiler.loopopts.superword.ReductionPerf
*/
package compiler.loopopts.superword;
public class ReductionPerf {
public static void main(String[] args) throws Exception {
int[] a1 = new int[8 * 1024];
int[] a2 = new int[8 * 1024];
int[] a3 = new int[8 * 1024];
long[] b1 = new long[8 * 1024];
long[] b2 = new long[8 * 1024];
long[] b3 = new long[8 * 1024];
float[] c1 = new float[8 * 1024];
float[] c2 = new float[8 * 1024];
float[] c3 = new float[8 * 1024];
double[] d1 = new double[8 * 1024];
double[] d2 = new double[8 * 1024];
double[] d3 = new double[8 * 1024];
ReductionInit(a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3);
int sumIv = sumInt(a1, a2, a3);
long sumLv = sumLong(b1, b2, b3);
float sumFv = sumFloat(c1, c2, c3);
double sumDv = sumDouble(d1, d2, d3);
int mulIv = prodInt(a1, a2, a3);
long mulLv = prodLong(b1, b2, b3);
float mulFv = prodFloat(c1, c2, c3);
double mulDv = prodDouble(d1, d2, d3);
int sumI = 0;
long sumL = 0;
float sumF = 0.f;
double sumD = 0.;
int mulI = 0;
long mulL = 0;
float mulF = 0.f;
double mulD = 0.;
System.out.println("Warmup ...");
long start = System.currentTimeMillis();
for (int j = 0; j < 2000; j++) {
sumI = sumInt(a1, a2, a3);
sumL = sumLong(b1, b2, b3);
sumF = sumFloat(c1, c2, c3);
sumD = sumDouble(d1, d2, d3);
mulI = prodInt(a1, a2, a3);
mulL = prodLong(b1, b2, b3);
mulF = prodFloat(c1, c2, c3);
mulD = prodDouble(d1, d2, d3);
}
long stop = System.currentTimeMillis();
System.out.println(" Warmup is done in " + (stop - start) + " msec");
if (sumIv != sumI) {
System.out.println("sum int: " + sumIv + " != " + sumI);
}
if (sumLv != sumL) {
System.out.println("sum long: " + sumLv + " != " + sumL);
}
if (sumFv != sumF) {
System.out.println("sum float: " + sumFv + " != " + sumF);
}
if (sumDv != sumD) {
System.out.println("sum double: " + sumDv + " != " + sumD);
}
if (mulIv != mulI) {
System.out.println("prod int: " + mulIv + " != " + mulI);
}
if (mulLv != mulL) {
System.out.println("prod long: " + mulLv + " != " + mulL);
}
if (mulFv != mulF) {
System.out.println("prod float: " + mulFv + " != " + mulF);
}
if (mulDv != mulD) {
System.out.println("prod double: " + mulDv + " != " + mulD);
}
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
sumI = sumInt(a1, a2, a3);
}
stop = System.currentTimeMillis();
System.out.println("sum int: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
sumL = sumLong(b1, b2, b3);
}
stop = System.currentTimeMillis();
System.out.println("sum long: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
sumF = sumFloat(c1, c2, c3);
}
stop = System.currentTimeMillis();
System.out.println("sum float: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
sumD = sumDouble(d1, d2, d3);
}
stop = System.currentTimeMillis();
System.out.println("sum double: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
mulI = prodInt(a1, a2, a3);
}
stop = System.currentTimeMillis();
System.out.println("prod int: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
mulL = prodLong(b1, b2, b3);
}
stop = System.currentTimeMillis();
System.out.println("prod long: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
mulF = prodFloat(c1, c2, c3);
}
stop = System.currentTimeMillis();
System.out.println("prod float: " + (stop - start));
start = System.currentTimeMillis();
for (int j = 0; j < 5000; j++) {
mulD = prodDouble(d1, d2, d3);
}
stop = System.currentTimeMillis();
System.out.println("prod double: " + (stop - start));
}
public static void ReductionInit(int[] a1, int[] a2, int[] a3,
long[] b1, long[] b2, long[] b3,
float[] c1, float[] c2, float[] c3,
double[] d1, double[] d2, double[] d3) {
for(int i = 0; i < a1.length; i++) {
a1[i] = (i + 0);
a2[i] = (i + 1);
a3[i] = (i + 2);
b1[i] = (long) (i + 0);
b2[i] = (long) (i + 1);
b3[i] = (long) (i + 2);
c1[i] = (float) (i + 0);
c2[i] = (float) (i + 1);
c3[i] = (float) (i + 2);
d1[i] = (double) (i + 0);
d2[i] = (double) (i + 1);
d3[i] = (double) (i + 2);
}
}
public static int sumInt(int[] a1, int[] a2, int[] a3) {
int total = 0;
for (int i = 0; i < a1.length; i++) {
total += (a1[i] * a2[i]) + (a1[i] * a3[i]) + (a2[i] * a3[i]);
}
return total;
}
public static long sumLong(long[] b1, long[] b2, long[] b3) {
long total = 0;
for (int i = 0; i < b1.length; i++) {
total += (b1[i] * b2[i]) + (b1[i] * b3[i]) + (b2[i] * b3[i]);
}
return total;
}
public static float sumFloat(float[] c1, float[] c2, float[] c3) {
float total = 0;
for (int i = 0; i < c1.length; i++) {
total += (c1[i] * c2[i]) + (c1[i] * c3[i]) + (c2[i] * c3[i]);
}
return total;
}
public static double sumDouble(double[] d1, double[] d2, double[] d3) {
double total = 0;
for (int i = 0; i < d1.length; i++) {
total += (d1[i] * d2[i]) + (d1[i] * d3[i]) + (d2[i] * d3[i]);
}
return total;
}
public static int prodInt(int[] a1, int[] a2, int[] a3) {
int total = 1;
for (int i = 0; i < a1.length; i++) {
total *= (a1[i] * a2[i]) + (a1[i] * a3[i]) + (a2[i] * a3[i]);
}
return total;
}
public static long prodLong(long[] b1, long[] b2, long[] b3) {
long total = 1;
for (int i = 0; i < b1.length; i++) {
total *= (b1[i] * b2[i]) + (b1[i] * b3[i]) + (b2[i] * b3[i]);
}
return total;
}
public static float prodFloat(float[] c1, float[] c2, float[] c3) {
float total = 1;
for (int i = 0; i < c1.length; i++) {
total *= (c1[i] * c2[i]) + (c1[i] * c3[i]) + (c2[i] * c3[i]);
}
return total;
}
public static double prodDouble(double[] d1, double[] d2, double[] d3) {
double total = 1;
for (int i = 0; i < d1.length; i++) {
total *= (d1[i] * d2[i]) + (d1[i] * d3[i]) + (d2[i] * d3[i]);
}
return total;
}
}
|