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 TestScalar {
  final int LOOP_CNT = 10000; 

  @Param("1024")
  int size;

  int[] ia, ib, ic;
  long[] la, lb, lc;

  public void testVectInit() {
    ia = new int[size];
    ib = new int[size];
    ic = new int[size];
    la = new long[size];
    lb = new long[size];
    lc = new long[size];
    for (int i = 0; i < size; i++) {
       ia[i] = -i;
       ib[i] = 500;
       la[i] = (long)-i;
       lb[i] = (long)500;
    }
  }

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

  @Benchmark
  public void testAbsI() {
     for (int n = 0; n < LOOP_CNT; n++) {
         for (int i = 0; i < ia.length; i += 4) {
             ic[i] = Math.abs(ia[i] + ib[i]);
         }
     }
  }
  
  @Benchmark
  public void testAbsL() {
     for (int n = 0; n < LOOP_CNT; n++) {
         for (int i = 0; i < la.length; i += 4) {
             lc[i] = Math.abs(la[i] + lb[i]);
         }
     }
  }
}
