diff options
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/vector/TestSIMDMulC.java')
-rw-r--r-- | src/main/java/org/linaro/benchmarks/vector/TestSIMDMulC.java | 85 |
1 files changed, 85 insertions, 0 deletions
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); + } + } + +} |