summaryrefslogtreecommitdiff
path: root/src/main/java/org/linaro/benchmarks/TestSimdAdd.java
blob: 18082d089b1903dd123989e767ad1e9d1aab245f (plain)
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
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 TestSimdAdd {
  static final int LENGTH = 1024 * 256;
  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];
  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);
    }
  }

  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]);
    }
  }

  @Setup
  public void setup()
  {
    TestSimdAddInit();
  }

  @Benchmark
  public void testVectAddByte() {
    vectAddByte();
  }

  @Benchmark
  public void testVectAddShort() {
    vectAddShort();
  }

  @Benchmark
  public void testVectAddInt() {
    vectAddInt();
  }

}