summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Zhang <yang.zhang@linaro.org>2016-09-18 17:09:03 +0800
committerNingsheng Jian <ningsheng.jian@linaro.org>2016-11-02 04:14:59 +0000
commit7de7b54b6f037e54fa2ce5d3a2939357a2e2ebb7 (patch)
treec3d936b11b581f7065e96fa3c7ddb68606de3257
parentc67ddb87c2062f4446d3e6ea21c13937521be7de (diff)
Add samples for int/short reduce_add instruction
Change-Id: I10084ceaa3860738cb9f8d9163c5e3cebbc04a33
-rw-r--r--src/main/java/org/linaro/benchmarks/TestReduceAdd.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/TestReduceAdd.java b/src/main/java/org/linaro/benchmarks/TestReduceAdd.java
new file mode 100644
index 0000000..118f185
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/TestReduceAdd.java
@@ -0,0 +1,104 @@
+package org.linaro.benchmarks;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestReduceAdd {
+ static final int LENGTH = 256 * 1024;
+ static int [] a = new int[LENGTH];
+ static int [] b = new int[LENGTH];
+ static short [] sa = new short[LENGTH];
+ static short [] sb = new short[LENGTH];
+
+ public static void TestReduceAddInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = 2;
+ b[i] = 1;
+ sa[i] = 2;
+ sb[i] = 1;
+ }
+ }
+
+ // In this case, addv sn vm.4s can't be generated in current jdk (OpenJDK9).
+ // hotspot version: changeset 12033:d5d5cd1adeaa
+ // The same with following test cases.
+ public static int reduceAddInt(int[] a, int[] b) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ total += a[i];
+ }
+ return total;
+ }
+
+ // In the following two cases, addv sn vm.4s can be generated.
+ // The operator can be sub, mul or other operators which can be
+ // vectorized easily.
+ public static int reduceAddSumofSubInt(int[] a, int[] b) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ total += (a[i] - b[i]);
+ }
+ return total;
+ }
+
+ public static int reduceAddSumofMulInt(int[] a, int[] b) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ total += (a[i] * b[i]);
+ }
+ return total;
+ }
+
+
+ // In the following three cases, addv hn vm.4h can't be generated.
+ public static int reduceAddShort(short[] a, short[] b) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ total += a[i];
+ }
+ return total;
+ }
+
+ public static int reduceAddSumofSubShort(short[] a, short[] b) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ total += (a[i] - b[i]);
+ }
+ return total;
+ }
+
+ public static int reduceAddSumofMulShort(short[] a, short[] b) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ total += (a[i] * b[i]);
+ }
+ return total;
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestReduceAddInit();
+ }
+
+ @Benchmark
+ public void testReduceAddInt() {
+ int sum;
+ sum = reduceAddInt(a, b);
+ sum = reduceAddSumofSubInt(a, b);
+ sum = reduceAddSumofMulInt(a, b);
+ }
+
+ @Benchmark
+ public void testReduceAddShort() {
+ int sum;
+ sum = reduceAddShort(sa, sb);
+ sum = reduceAddSumofSubShort(sa, sb);
+ sum = reduceAddSumofMulShort(sa, sb);
+ }
+
+}