summaryrefslogtreecommitdiff
path: root/src/main/java/org/linaro/benchmarks/vector
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/vector')
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestRGBToCmyk.java73
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestReduceAdd.java127
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDAdd.java155
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDCopy.java142
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDFma.java223
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDLd2St2.java114
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDLd3St3.java122
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDLd4St4.java130
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaInt.java111
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaShort.java161
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDMul.java155
-rw-r--r--src/main/java/org/linaro/benchmarks/vector/TestSIMDMulC.java85
12 files changed, 1598 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestRGBToCmyk.java b/src/main/java/org/linaro/benchmarks/vector/TestRGBToCmyk.java
new file mode 100644
index 0000000..e56a356
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestRGBToCmyk.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestRGBToCmyk
+{
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static byte input[] = new byte[LENGTH*3];
+ static byte output[] = new byte[LENGTH*4];
+
+ public static void TestRGBToCmykInit()
+ {
+ for (int i = 0; i < LENGTH*3; i++) {
+ input[i] = (byte)i;
+ }
+ }
+
+ public static void RGBToCmyk(byte[] rgb, byte[] cmyk, int cnt)
+ {
+ int i;
+ int c, m, y, k;
+ for (i = 0; i < cnt; i++) {
+ /* calculate complementary colors */
+ c = 255 - rgb[i*3];
+ m = 255 - rgb[i*3+1];
+ y = 255 - rgb[i*3+2];
+ /* find the black level k */
+ k = Math.min(Math.min(c, m), y);
+ /* correct complementary color lever based on k */
+ cmyk[i*4] = (byte)(c - k);
+ cmyk[i*4+1] = (byte)(m - k);
+ cmyk[i*4+2] = (byte)(y - k);
+ cmyk[i*4+3] = (byte)(k);
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestRGBToCmykInit();
+ }
+
+ @Benchmark
+ public void testRGBToCmyk() {
+ for (int i = 0; i < COUNT; i++) {
+ RGBToCmyk(input, output, LENGTH);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestReduceAdd.java b/src/main/java/org/linaro/benchmarks/vector/TestReduceAdd.java
new file mode 100644
index 0000000..679fac4
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestReduceAdd.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+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 = 1024;
+ static final int COUNT = 2000;
+ static int [] a = new int[LENGTH];
+ static int [] b = new int[LENGTH];
+ static short [] sa = new short[LENGTH];
+ static short [] sb = new short[LENGTH];
+ static int result = 0;
+ 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 = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += reduceAddInt(a, b);
+ sum += reduceAddSumofSubInt(a, b);
+ sum += reduceAddSumofMulInt(a, b);
+ }
+ result += sum;
+ }
+
+ @Benchmark
+ public void testReduceAddShort() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += reduceAddShort(sa, sb);
+ sum += reduceAddSumofSubShort(sa, sb);
+ sum += reduceAddSumofMulShort(sa, sb);
+ }
+ result += sum;
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDAdd.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDAdd.java
new file mode 100644
index 0000000..a7c69b4
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDAdd.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDAdd {
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static int [] a = new int[LENGTH];
+ static int [] b = new int[LENGTH];
+ static int [] c = new int[LENGTH];
+ static short [] sa = new short[LENGTH];
+ static short [] sb = new short[LENGTH];
+ static short [] sc = new short[LENGTH];
+ static byte [] ba = new byte[LENGTH];
+ static byte [] bb = new byte[LENGTH];
+ static byte [] bc = new byte[LENGTH];
+ static long [] la = new long[LENGTH];
+ static long [] lb = new long[LENGTH];
+ static long [] lc = new long[LENGTH];
+ static float [] fa = new float[LENGTH];
+ static float [] fb = new float[LENGTH];
+ static float [] fc = new float[LENGTH];
+ static double [] da = new double[LENGTH];
+ static double [] db = new double[LENGTH];
+ static double [] dc = new double[LENGTH];
+
+ public static void TestSIMDAddInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = i + 3;
+ b[i] = i + 2;
+ c[i] = i + 1;
+ sa[i] = (short)(i + 3);
+ sb[i] = (short)(i + 2);
+ sc[i] = (short)(i + 1);
+ ba[i] = (byte)(i + 3);
+ bb[i] = (byte)(i + 2);
+ bc[i] = (byte)(i + 1);
+ la[i] = (long)(i + 3);
+ lb[i] = (long)(i + 2);
+ lc[i] = (long)(i + 1);
+ fa[i] = (float)(i + 3);
+ fb[i] = (float)(i + 2);
+ fc[i] = (float)(i + 1);
+ da[i] = (double)(i + 3);
+ db[i] = (double)(i + 2);
+ dc[i] = (double)(i + 1);
+ }
+ }
+
+ public static void vectAddInt() {
+ for (int i = 0; i < LENGTH; i++) {
+ c[i] = a[i] + b[i];
+ }
+ }
+
+ public static void vectAddShort() {
+ for (int i = 0; i < LENGTH; i++) {
+ sc[i] = (short)(sa[i] + sb[i]);
+ }
+ }
+
+ public static void vectAddByte() {
+ for (int i = 0; i < LENGTH; i++) {
+ bc[i] = (byte)(ba[i] + bb[i]);
+ }
+ }
+
+ public static void vectAddLong() {
+ for (int i = 0; i < LENGTH; i++) {
+ lc[i] = la[i] + lb[i];
+ }
+ }
+
+ public static void vectAddFloat() {
+ for (int i = 0; i < LENGTH; i++) {
+ fc[i] = fa[i] + fb[i];
+ }
+ }
+
+ public static void vectAddDouble() {
+ for (int i = 0; i < LENGTH; i++) {
+ dc[i] = da[i] + db[i];
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestSIMDAddInit();
+ }
+
+ @Benchmark
+ public void testVectAddByte() {
+ for (int i = 0; i < COUNT; i++) {
+ vectAddByte();
+ }
+ }
+
+ @Benchmark
+ public void testVectAddShort() {
+ for (int i = 0; i < COUNT; i++) {
+ vectAddShort();
+ }
+ }
+
+ @Benchmark
+ public void testVectAddInt() {
+ for (int i = 0; i < COUNT; i++) {
+ vectAddInt();
+ }
+ }
+
+ @Benchmark
+ public void testVectAddLong() {
+ for (int i = 0; i < COUNT; i++) {
+ vectAddLong();
+ }
+ }
+
+ @Benchmark
+ public void testVectAddFloat() {
+ for (int i = 0; i < COUNT; i++) {
+ vectAddFloat();
+ }
+ }
+
+ @Benchmark
+ public void testVectAddDouble() {
+ for (int i = 0; i < COUNT; i++) {
+ vectAddDouble();
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDCopy.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDCopy.java
new file mode 100644
index 0000000..8619ff4
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDCopy.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDCopy {
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static int [] a = new int[LENGTH];
+ static int [] c = new int[LENGTH];
+ static short [] sa = new short[LENGTH];
+ static short [] sc = new short[LENGTH];
+ static byte [] ba = new byte[LENGTH];
+ static byte [] bc = new byte[LENGTH];
+ static long [] la = new long[LENGTH];
+ static long [] lc = new long[LENGTH];
+ static float [] fa = new float[LENGTH];
+ static float [] fc = new float[LENGTH];
+ static double [] da = new double[LENGTH];
+ static double [] dc = new double[LENGTH];
+
+ public static void TestSIMDCopyInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = i + 3;
+ c[i] = i + 1;
+ sa[i] = (short)(i + 3);
+ sc[i] = (short)(i + 1);
+ ba[i] = (byte)(i + 3);
+ bc[i] = (byte)(i + 1);
+ la[i] = (long)(i + 3);
+ lc[i] = (long)(i + 1);
+ fa[i] = (float)(i + 3);
+ fc[i] = (float)(i + 1);
+ da[i] = (double)(i + 3);
+ dc[i] = (double)(i + 1);
+ }
+ }
+
+ public static void vectCopyInt() {
+ for (int i = 0; i < LENGTH; i++) {
+ c[i] = a[i];
+ }
+ }
+
+ public static void vectCopyShort() {
+ for (int i = 0; i < LENGTH; i++) {
+ sc[i] = sa[i];
+ }
+ }
+
+ public static void vectCopyByte() {
+ for (int i = 0; i < LENGTH; i++) {
+ bc[i] = ba[i];
+ }
+ }
+
+ public static void vectCopyLong() {
+ for (int i = 0; i < LENGTH; i++) {
+ lc[i] = la[i];
+ }
+ }
+
+ public static void vectCopyFloat() {
+ for (int i = 0; i < LENGTH; i++) {
+ fc[i] = fa[i];
+ }
+ }
+
+ public static void vectCopyDouble() {
+ for (int i = 0; i < LENGTH; i++) {
+ dc[i] = da[i];
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestSIMDCopyInit();
+ }
+
+ @Benchmark
+ public void testVectCopyByte() {
+ for (int i = 0; i < COUNT; i++) {
+ vectCopyByte();
+ }
+ }
+
+ @Benchmark
+ public void testVectCopyShort() {
+ for (int i = 0; i < COUNT; i++) {
+ vectCopyShort();
+ }
+ }
+
+ @Benchmark
+ public void testVectCopyInt() {
+ for (int i = 0; i < COUNT; i++) {
+ vectCopyInt();
+ }
+ }
+
+ @Benchmark
+ public void testVectCopyLong() {
+ for (int i = 0; i < COUNT; i++) {
+ vectCopyLong();
+ }
+ }
+
+ @Benchmark
+ public void testVectCopyFloat() {
+ for (int i = 0; i < COUNT; i++) {
+ vectCopyFloat();
+ }
+ }
+
+ @Benchmark
+ public void testVectCopyDouble() {
+ for (int i = 0; i < COUNT; i++) {
+ vectCopyDouble();
+ }
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDFma.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDFma.java
new file mode 100644
index 0000000..336ea87
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDFma.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2017 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDFma {
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static float [] fa = new float[LENGTH];
+ static float [] fb = new float[LENGTH];
+ static float [] fc = new float[LENGTH];
+ static double [] da = new double[LENGTH];
+ static double [] db = new double[LENGTH];
+ static double [] dc = new double[LENGTH];
+
+ public static void testSIMDFmaInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ fa[i] = (float)(i + 3);
+ fb[i] = (float)(i + 2);
+ fc[i] = (float)(i + 1);
+ da[i] = (double)(i + 3);
+ db[i] = (double)(i + 2);
+ dc[i] = (double)(i + 1);
+ }
+ }
+
+ public static void vecFusedMulAddFloat(
+ float[] a,
+ float[] b,
+ float[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(a[i], b[i], c[i]);
+ }
+ }
+
+ public static void vecFusedMulSub1Float(
+ float[] a,
+ float[] b,
+ float[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(-a[i], b[i], c[i]);
+ }
+ }
+
+ public static void vecFusedMulSub2Float(
+ float[] a,
+ float[] b,
+ float[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(a[i], -b[i], c[i]);
+ }
+ }
+
+ public static void vecNegFusedMulSubFloat(
+ float[] a,
+ float[] b,
+ float[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(a[i], b[i], -c[i]);
+ }
+ }
+
+ public static void vecNegFusedMulAddFloat(
+ float[] a,
+ float[] b,
+ float[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = -(Math.fma(a[i], b[i], c[i]));
+ }
+ }
+
+ public static void vecFusedMulAddDouble(
+ double[] a,
+ double[] b,
+ double[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(a[i], b[i], c[i]);
+ }
+ }
+
+ public static void vecFusedMulSub1Double(
+ double[] a,
+ double[] b,
+ double[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(-a[i], b[i], c[i]);
+ }
+ }
+
+ public static void vecFusedMulSub2Double(
+ double[] a,
+ double[] b,
+ double[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(a[i], -b[i], c[i]);
+ }
+ }
+
+ public static void vecNegFusedMulSubDouble(
+ double[] a,
+ double[] b,
+ double[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = Math.fma(a[i], b[i], -c[i]);
+ }
+ }
+
+ public static void vecNegFusedMulAddDouble(
+ double[] a,
+ double[] b,
+ double[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ c[i] = -(Math.fma(a[i], b[i], c[i]));
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ testSIMDFmaInit();
+ }
+
+ @Benchmark
+ public void testVecFusedMulAddFloat() {
+ for (int i = 0; i < COUNT; i++) {
+ vecFusedMulAddFloat(fa, fb, fc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecFusedMulSub1Float() {
+ for (int i = 0; i < COUNT; i++) {
+ vecFusedMulSub1Float(fa, fb, fc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecFusedMulSub2Float() {
+ for (int i = 0; i < COUNT; i++) {
+ vecFusedMulSub2Float(fa, fb, fc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecNegFusedMulAddFloat() {
+ for (int i = 0; i < COUNT; i++) {
+ vecNegFusedMulAddFloat(fa, fb, fc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecNegFusedMulSubFloat() {
+ for (int i = 0; i < COUNT; i++) {
+ vecNegFusedMulSubFloat(fa, fb, fc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecFusedMulAddDouble() {
+ for (int i = 0; i < COUNT; i++) {
+ vecFusedMulAddDouble(da, db, dc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecFusedMulSub1Double() {
+ for (int i = 0; i < COUNT; i++) {
+ vecFusedMulSub1Double(da, db, dc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecFusedMulSub2Double() {
+ for (int i = 0; i < COUNT; i++) {
+ vecFusedMulSub2Double(da, db, dc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecNegFusedMulAddDouble() {
+ for (int i = 0; i < COUNT; i++) {
+ vecNegFusedMulAddDouble(da, db, dc, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testVecNegFusedMulSubDouble() {
+ for (int i = 0; i < COUNT; i++) {
+ vecNegFusedMulSubDouble(da, db, dc, LENGTH);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd2St2.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd2St2.java
new file mode 100644
index 0000000..7e99698
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd2St2.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDLd2St2 {
+ static final int VECT_LENGTH = 1024;
+ static final int COUNT = 128;
+ static final int DIM = 2;
+ static final int LENGTH = VECT_LENGTH * DIM;
+ static int [] in = new int[LENGTH];
+ static int [] out = new int[LENGTH];
+ static int [] c = new int[DIM];
+ static short [] sin = new short[LENGTH];
+ static short [] sout = new short[LENGTH];
+ static short [] sc = new short[DIM];
+
+ public static void vect2DInit() {
+ int i;
+ for (i = 0; i < LENGTH; i++) {
+ in[i] = i + 3;
+ sin[i] = (short)(i + 3);
+ }
+ for (i = 0; i < DIM; i++) {
+ c[i] = i + 1;
+ sc[i] = (short)(i + 1);
+ }
+ }
+
+ public static void vect2DAddInt(
+ int[] out,
+ int[] in,
+ int[] c) {
+ int c0 = c[0];
+ int c1 = c[1];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = in[i*DIM] + c0;
+ out[i*DIM + 1] = in[i*DIM + 1] + c1;
+ }
+ }
+
+ public static void vect2DMulInt(
+ int[] out,
+ int[] in,
+ int[] c) {
+ int c0 = c[0];
+ int c1 = c[1];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = in[i*DIM] * c0;
+ out[i*DIM + 1] = in[i*DIM + 1] * c1;
+ }
+ }
+
+ public static void vect2DAddShort(
+ short[] out,
+ short[] in,
+ short[] c) {
+ short c0 = c[0];
+ short c1 = c[1];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = (short)(in[i*DIM] + c0);
+ out[i*DIM + 1] = (short)(in[i*DIM + 1] + c1);
+ }
+ }
+
+ public static void vect2DMulShort(
+ short[] out,
+ short[] in,
+ short[] c) {
+ short c0 = c[0];
+ short c1 = c[1];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = (short)(in[i*DIM] * c0);
+ out[i*DIM + 1] = (short)(in[i*DIM + 1] * c1);
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ vect2DInit();
+ }
+
+ @Benchmark
+ public void testVect2D() {
+ for (int i = 0; i < COUNT; i++) {
+ vect2DAddInt(out, in, c);
+ vect2DMulInt(out, in, c);
+ vect2DAddShort(sout, sin, sc);
+ vect2DMulShort(sout, sin, sc);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd3St3.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd3St3.java
new file mode 100644
index 0000000..b2b6265
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd3St3.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDLd3St3 {
+ static final int VECT_LENGTH = 1024;
+ static final int COUNT = 128;
+ static final int DIM = 3;
+ static final int LENGTH = VECT_LENGTH * DIM;
+ static int [] in = new int[LENGTH];
+ static int [] out = new int[LENGTH];
+ static int [] c = new int[DIM];
+ static short [] sin = new short[LENGTH];
+ static short [] sout = new short[LENGTH];
+ static short [] sc = new short[DIM];
+
+ public static void vect3DInit() {
+ int i;
+ for (i = 0; i < LENGTH; i++) {
+ in[i] = i + 3;
+ sin[i] = (short)(i + 3);
+ }
+ for (i = 0; i < DIM; i++) {
+ c[i] = i + 1;
+ sc[i] = (short)(i + 1);
+ }
+ }
+
+ public static void vect3DAddInt(
+ int[] out,
+ int[] in,
+ int[] c) {
+ int c0 = c[0];
+ int c1 = c[1];
+ int c2 = c[2];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = in[i*DIM] + c0;
+ out[i*DIM + 1] = in[i*DIM + 1] + c1;
+ out[i*DIM + 2] = in[i*DIM + 2] + c2;
+ }
+ }
+
+ public static void vect3DMulInt(
+ int[] out,
+ int[] in,
+ int[] c) {
+ int c0 = c[0];
+ int c1 = c[1];
+ int c2 = c[2];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = in[i*DIM] * c0;
+ out[i*DIM + 1] = in[i*DIM + 1] * c1;
+ out[i*DIM + 2] = in[i*DIM + 2] * c2;
+ }
+ }
+
+ public static void vect3DAddShort(
+ short[] out,
+ short[] in,
+ short[] c) {
+ short c0 = c[0];
+ short c1 = c[1];
+ short c2 = c[2];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = (short)(in[i*DIM] + c0);
+ out[i*DIM + 1] = (short)(in[i*DIM + 1] + c1);
+ out[i*DIM + 2] = (short)(in[i*DIM + 2] + c2);
+ }
+ }
+
+ public static void vect3DMulShort(
+ short[] out,
+ short[] in,
+ short[] c) {
+ short c0 = c[0];
+ short c1 = c[1];
+ short c2 = c[2];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = (short)(in[i*DIM] * c0);
+ out[i*DIM + 1] = (short)(in[i*DIM + 1] * c1);
+ out[i*DIM + 2] = (short)(in[i*DIM + 2] * c2);
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ vect3DInit();
+ }
+
+ @Benchmark
+ public void testVect3D() {
+ for (int i = 0; i < COUNT; i++) {
+ vect3DAddInt(out, in, c);
+ vect3DMulInt(out, in, c);
+ vect3DAddShort(sout, sin, sc);
+ vect3DMulShort(sout, sin, sc);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd4St4.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd4St4.java
new file mode 100644
index 0000000..e53075c
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDLd4St4.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDLd4St4 {
+ static final int VECT_LENGTH = 1024;
+ static final int COUNT = 128;
+ static final int DIM = 4;
+ static final int LENGTH = VECT_LENGTH * DIM;
+ static int [] in = new int[LENGTH];
+ static int [] out = new int[LENGTH];
+ static int [] c = new int[DIM];
+ static short [] sin = new short[LENGTH];
+ static short [] sout = new short[LENGTH];
+ static short [] sc = new short[DIM];
+
+ public static void vect4DInit() {
+ int i;
+ for (i = 0; i < LENGTH; i++) {
+ in[i] = i + 3;
+ sin[i] = (short)(i + 3);
+ }
+ for (i = 0; i < DIM; i++) {
+ c[i] = i + 1;
+ sc[i] = (short)(i + 1);
+ }
+ }
+
+ public static void vect4DAddInt(
+ int[] out,
+ int[] in,
+ int[] c) {
+ int c0 = c[0];
+ int c1 = c[1];
+ int c2 = c[2];
+ int c3 = c[3];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = in[i*DIM] + c0;
+ out[i*DIM + 1] = in[i*DIM + 1] + c1;
+ out[i*DIM + 2] = in[i*DIM + 2] + c2;
+ out[i*DIM + 3] = in[i*DIM + 3] + c3;
+ }
+ }
+
+ public static void vect4DMulInt(
+ int[] out,
+ int[] in,
+ int[] c) {
+ int c0 = c[0];
+ int c1 = c[1];
+ int c2 = c[2];
+ int c3 = c[3];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = in[i*DIM] * c0;
+ out[i*DIM + 1] = in[i*DIM + 1] * c1;
+ out[i*DIM + 2] = in[i*DIM + 2] * c2;
+ out[i*DIM + 3] = in[i*DIM + 3] * c3;
+ }
+ }
+
+ public static void vect4DAddShort(
+ short[] out,
+ short[] in,
+ short[] c) {
+ short c0 = c[0];
+ short c1 = c[1];
+ short c2 = c[2];
+ short c3 = c[3];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = (short)(in[i*DIM] + c0);
+ out[i*DIM + 1] = (short)(in[i*DIM + 1] + c1);
+ out[i*DIM + 2] = (short)(in[i*DIM + 2] + c2);
+ out[i*DIM + 3] = (short)(in[i*DIM + 3] + c3);
+ }
+ }
+
+ public static void vect4DMulShort(
+ short[] out,
+ short[] in,
+ short[] c) {
+ short c0 = c[0];
+ short c1 = c[1];
+ short c2 = c[2];
+ short c3 = c[3];
+ for (int i = 0; i < VECT_LENGTH; i++) {
+ out[i*DIM] = (short)(in[i*DIM] * c0);
+ out[i*DIM + 1] = (short)(in[i*DIM + 1] * c1);
+ out[i*DIM + 2] = (short)(in[i*DIM + 2] * c2);
+ out[i*DIM + 3] = (short)(in[i*DIM + 3] * c3);
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ vect4DInit();
+ }
+
+ @Benchmark
+ public void testVect4D() {
+ for (int i = 0; i < COUNT; i++) {
+ vect4DAddInt(out, in, c);
+ vect4DMulInt(out, in, c);
+ vect4DAddShort(sout, sin, sc);
+ vect4DMulShort(sout, sin, sc);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaInt.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaInt.java
new file mode 100644
index 0000000..08b1f22
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaInt.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDMlaInt {
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static int [] a = new int[LENGTH];
+ static int [] b = new int[LENGTH];
+ static int [] c = new int[LENGTH];
+ static int [] d = new int[LENGTH];
+
+ public static void TestSIMDMlaInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = 3;
+ b[i] = 2;
+ c[i] = 1;
+ }
+ }
+
+ public static int vectSumOfMulAdd1(
+ int[] a,
+ int[] b,
+ int[] c,
+ int[] d) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (int)(a[i] * b[i] + c[i]);
+ total += d[i];
+ }
+ return total;
+ }
+
+ public static int vectSumOfMulAdd2(
+ int[] a,
+ int[] b,
+ int[] c,
+ int[] d) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (int)(a[i] * b[i] + a[i] * c[i]);
+ total += d[i];
+ }
+ return total;
+ }
+
+ public static int vectSumOfMulAdd3(
+ int[] a,
+ int[] b,
+ int[] c,
+ int[] d) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (int)((a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]));
+ total += d[i];
+ }
+ return total;
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestSIMDMlaInit();
+ }
+
+ @Benchmark
+ public void testVectSumOfMulAdd1() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += vectSumOfMulAdd1(a, b, c, d);
+ }
+ }
+
+ @Benchmark
+ public void testVectSumOfMulAdd2() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += vectSumOfMulAdd2(a, b, c, d);
+ }
+ }
+
+ @Benchmark
+ public void testVectSumOfMulAdd3() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += vectSumOfMulAdd3(a, b, c, d);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaShort.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaShort.java
new file mode 100644
index 0000000..68e27d5
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMlaShort.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDMlaShort {
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static short [] a = new short[LENGTH];
+ static short [] b = new short[LENGTH];
+ static short [] c = new short[LENGTH];
+ static short [] d = new short[LENGTH];
+
+ public static void TestSIMDMlaInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = 3;
+ b[i] = 2;
+ c[i] = 1;
+ }
+ }
+
+ public static int vectSumOfMulAdd1(
+ short[] a,
+ short[] b,
+ short[] c,
+ short[] d) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (short)(a[i] * b[i] + c[i]);
+ total += d[i];
+ }
+ return total;
+ }
+
+ public static int vectSumOfMulAdd2(
+ short[] a,
+ short[] b,
+ short[] c,
+ short[] d) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (short)(a[i] * b[i] + a[i] * c[i]);
+ total += d[i];
+ }
+ return total;
+ }
+
+ public static int vectSumOfMulAdd3(
+ short[] a,
+ short[] b,
+ short[] c,
+ short[] d) {
+ int total = 0;
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (short)((a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]));
+ total += d[i];
+ }
+ return total;
+ }
+
+ public static void vectMulAdd1(
+ short[] a,
+ short[] b,
+ short[] c,
+ short[] d) {
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (short)(a[i] * b[i] + c[i]);
+ }
+ }
+
+ public static void vectMulAdd2(
+ short[] a,
+ short[] b,
+ short[] c,
+ short[] d) {
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (short)(a[i] * b[i] + a[i] * c[i]);
+ }
+ }
+
+ public static void vectMulAdd3(
+ short[] a,
+ short[] b,
+ short[] c,
+ short[] d) {
+ for (int i = 0; i < LENGTH; i++) {
+ d[i] = (short)((a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]));
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestSIMDMlaInit();
+ }
+
+ @Benchmark
+ public void testVectSumOfMulAdd1() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += vectSumOfMulAdd1(a, b, c, d);
+ }
+ }
+
+ @Benchmark
+ public void testVectSumOfMulAdd2() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += vectSumOfMulAdd2(a, b, c, d);
+ }
+ }
+
+ @Benchmark
+ public void testVectSumOfMulAdd3() {
+ int sum = 0;
+ for (int i = 0; i < COUNT; i++) {
+ sum += vectSumOfMulAdd3(a, b, c, d);
+ }
+ }
+ @Benchmark
+ public void testVectMulAdd1() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulAdd1(a, b, c, d);
+ }
+ }
+
+ @Benchmark
+ public void testVectMulAdd2() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulAdd2(a, b, c, d);
+ }
+ }
+
+ @Benchmark
+ public void testVectMulAdd3() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulAdd3(a, b, c, d);
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDMul.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMul.java
new file mode 100644
index 0000000..3210e8d
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMul.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2016 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDMul {
+ static final int LENGTH = 1024;
+ static final int COUNT = 128;
+ static int [] a = new int[LENGTH];
+ static int [] b = new int[LENGTH];
+ static int [] c = new int[LENGTH];
+ static short [] sa = new short[LENGTH];
+ static short [] sb = new short[LENGTH];
+ static short [] sc = new short[LENGTH];
+ static byte [] ba = new byte[LENGTH];
+ static byte [] bb = new byte[LENGTH];
+ static byte [] bc = new byte[LENGTH];
+ static long [] la = new long[LENGTH];
+ static long [] lb = new long[LENGTH];
+ static long [] lc = new long[LENGTH];
+ static float [] fa = new float[LENGTH];
+ static float [] fb = new float[LENGTH];
+ static float [] fc = new float[LENGTH];
+ static double [] da = new double[LENGTH];
+ static double [] db = new double[LENGTH];
+ static double [] dc = new double[LENGTH];
+
+ public static void TestSIMDMulInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = i + 3;
+ b[i] = i + 2;
+ c[i] = i + 1;
+ sa[i] = (short)(i + 3);
+ sb[i] = (short)(i + 2);
+ sc[i] = (short)(i + 1);
+ ba[i] = (byte)(i + 3);
+ bb[i] = (byte)(i + 2);
+ bc[i] = (byte)(i + 1);
+ la[i] = (long)(i + 3);
+ lb[i] = (long)(i + 2);
+ lc[i] = (long)(i + 1);
+ fa[i] = (float)(i + 3);
+ fb[i] = (float)(i + 2);
+ fc[i] = (float)(i + 1);
+ da[i] = (double)(i + 3);
+ db[i] = (double)(i + 2);
+ dc[i] = (double)(i + 1);
+ }
+ }
+
+ public static void vectMulInt() {
+ for (int i = 0; i < LENGTH; i++) {
+ c[i] = a[i] * b[i];
+ }
+ }
+
+ public static void vectMulShort() {
+ for (int i = 0; i < LENGTH; i++) {
+ sc[i] = (short)(sa[i] * sb[i]);
+ }
+ }
+
+ public static void vectMulByte() {
+ for (int i = 0; i < LENGTH; i++) {
+ bc[i] = (byte)(ba[i] * bb[i]);
+ }
+ }
+
+ public static void vectMulLong() {
+ for (int i = 0; i < LENGTH; i++) {
+ lc[i] = la[i] * lb[i];
+ }
+ }
+
+ public static void vectMulFloat() {
+ for (int i = 0; i < LENGTH; i++) {
+ fc[i] = fa[i] * fb[i];
+ }
+ }
+
+ public static void vectMulDouble() {
+ for (int i = 0; i < LENGTH; i++) {
+ dc[i] = da[i] * db[i];
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ TestSIMDMulInit();
+ }
+
+ @Benchmark
+ public void testVectMulByte() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulByte();
+ }
+ }
+
+ @Benchmark
+ public void testVectMulShort() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulShort();
+ }
+ }
+
+ @Benchmark
+ public void tesVectMulInt() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulInt();
+ }
+ }
+
+ @Benchmark
+ public void testVectMulLong() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulLong();
+ }
+ }
+
+ @Benchmark
+ public void testVectMulFloat() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulFloat();
+ }
+ }
+
+ @Benchmark
+ public void testVectMulDouble() {
+ for (int i = 0; i < COUNT; i++) {
+ vectMulDouble();
+ }
+ }
+
+}
diff --git a/src/main/java/org/linaro/benchmarks/vector/TestSIMDMulC.java b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMulC.java
new file mode 100644
index 0000000..1b75325
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/vector/TestSIMDMulC.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2017 Linaro Limited. All rights received.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.linaro.benchmarks.vector;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class TestSIMDMulC {
+ static final int LENGTH = 1024;
+ static final int COUNT = 200;
+ static int [] a = new int[LENGTH];
+ static int [] b = new int[LENGTH];
+ static int [] c = new int[LENGTH];
+
+ public static void testSIMDMulCInit() {
+ for (int i = 0; i < LENGTH; i++) {
+ a[i] = i + 3;
+ b[i] = i + 2;
+ c[i] = i + 1;
+ }
+ }
+
+ public static void mulCInt1(
+ int[] a,
+ int[] b,
+ int[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ int t0 = a[i] * 5;
+ int t1 = b[i] * 10;
+ c[i] = t0 + t1;
+ }
+ }
+
+ public static void mulCInt2(
+ int[] a,
+ int[] b,
+ int[] c,
+ int loop) {
+ for (int i = 0; i < loop; i++) {
+ int t0 = a[i] * 9;
+ int t1 = b[i] * 17;
+ c[i] = t0 + t1;
+ }
+ }
+
+ @Setup
+ public void setup()
+ {
+ testSIMDMulCInit();
+ }
+
+ @Benchmark
+ public void testSIMDMulCInt1() {
+ for (int i = 0; i < COUNT; i++) {
+ mulCInt1(a, b, c, LENGTH);
+ }
+ }
+
+ @Benchmark
+ public void testSIMDMulCInt2() {
+ for (int i = 0; i < COUNT; i++) {
+ mulCInt2(a, b, c, LENGTH);
+ }
+ }
+
+}