summaryrefslogtreecommitdiff
path: root/src/main/java/org/linaro/benchmarks/stanford
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/stanford')
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Bubblesort.java81
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/IntMM.java75
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Oscar.java168
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Perm.java68
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Puzzle.java128
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Queens.java80
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Quicksort.java87
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/RealMM.java68
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Towers.java128
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Treesort.java108
10 files changed, 991 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Bubblesort.java b/src/main/java/org/linaro/benchmarks/stanford/Bubblesort.java
new file mode 100644
index 0000000..e53d9b9
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Bubblesort.java
@@ -0,0 +1,81 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Bubblesort {
+
+ private static final int sortelements = 5000;
+ private static final int srtelements = 500;
+
+ private boolean error; // Used as flag for the verify() function.
+ private long seed;
+ private int[] sortlist = new int [sortelements + 1];
+ private int biggest;
+ private int littlest;
+ private int top;
+
+// CHECKSTYLE.OFF: .*
+void Initrand () {
+ seed = 74755L; /* constant to long WR*/
+}
+
+int Rand () {
+ seed = (seed * 1309L + 13849L) & 65535L; /* constants to long WR*/
+ return( (int)seed ); /* typecast back to int WR*/
+}
+
+
+ /* Sorts an array using bubblesort */
+
+void bInitarr() {
+ int i;
+ long temp; /* converted temp to long for 16 bit WR*/
+ Initrand();
+ biggest = 0; littlest = 0;
+ for ( i = 1; i <= srtelements; i++ ) {
+ temp = Rand();
+ /* converted constants to long in next stmt, typecast back to int WR*/
+ sortlist[i] = (int)(temp - (temp/100000L)*100000L - 50000L);
+ if ( sortlist[i] > biggest ) biggest = sortlist[i];
+ else if ( sortlist[i] < littlest ) littlest = sortlist[i];
+ }
+}
+
+void Bubble() {
+ int i, j;
+ bInitarr();
+ top=srtelements;
+
+ while ( top>1 ) {
+
+ i=1;
+ while ( i<top ) {
+
+ if ( sortlist[i] > sortlist[i+1] ) {
+ j = sortlist[i];
+ sortlist[i] = sortlist[i+1];
+ sortlist[i+1] = j;
+ }
+ i=i+1;
+ }
+
+ top=top-1;
+ }
+ if ( (sortlist[1] != littlest) || (sortlist[srtelements] != biggest) )
+ error = true;
+}
+ // CHECKSTYLE.ON: .*
+ @Benchmark
+ public void jmhTimeBubble() {
+ Bubble();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/IntMM.java b/src/main/java/org/linaro/benchmarks/stanford/IntMM.java
new file mode 100644
index 0000000..52ab141
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/IntMM.java
@@ -0,0 +1,75 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class IntMM {
+
+ private static final int rowsize = 40;
+
+ // Number of (internal) iterations for IntMM runs as per original benchmark
+ private static final int INTMM_ITERS = 10;
+ private static final int EXPECTED = 300;
+
+ private long seed;
+
+ private int[][] ima = new int[rowsize + 1][rowsize + 1];
+ private int[][] imb = new int[rowsize + 1][rowsize + 1];
+ private int[][] imr = new int[rowsize + 1][rowsize + 1];
+
+// CHECKSTYLE.OFF: .*
+void Initrand () {
+ seed = 74755L; /* constant to long WR*/
+}
+
+int Rand () {
+ seed = (seed * 1309L + 13849L) & 65535L; /* constants to long WR*/
+ return( (int)seed ); /* typecast back to int WR*/
+}
+
+
+ /* Multiplies two integer matrices. */
+
+private void Initmatrix (int m[][]) {
+ int temp, i, j;
+ for ( i = 1; i <= rowsize; i++ )
+ for ( j = 1; j <= rowsize; j++ ) {
+ temp = Rand();
+ m[i][j] = temp - (temp/120)*120 - 60;
+ }
+}
+
+void Innerproduct( int result[][], int a[][], int b[][], int row, int column) {
+ /* computes the inner product of A[row,*] and B[*,column] */
+ int i;
+ int tmp = 0;
+ for(i = 1; i <= rowsize; i++ ) tmp = tmp+a[row][i]*b[i][column];
+ result[row][column] = tmp;
+ }
+
+void Intmm (int run) {
+ int i, j;
+ Initrand();
+ Initmatrix (ima);
+ Initmatrix (imb);
+ for ( i = 1; i <= rowsize; i++ )
+ for ( j = 1; j <= rowsize; j++ )
+ Innerproduct(imr,ima,imb,i,j);
+}
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimeIntmm() {
+ for (int j = 0; j < INTMM_ITERS; j++) {
+ Intmm(j);
+ }
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Oscar.java b/src/main/java/org/linaro/benchmarks/stanford/Oscar.java
new file mode 100644
index 0000000..5388366
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Oscar.java
@@ -0,0 +1,168 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Oscar {
+
+ private static final int fftsize = 256;
+ private static final int fftsize2 = 129;
+
+ class Complex {
+ float rp;
+ float ip;
+ }
+
+ private Complex[] z = new Complex [fftsize + 1];
+ private Complex[] w = new Complex [fftsize + 1];
+ private Complex[] e = new Complex [fftsize2 + 1];
+ private float zr;
+ private float zi;
+ private float[] h = new float[26];
+
+ private long seed; /* converted to long for 16 bit WR*/
+
+ public Oscar() {
+ for (int i = 0; i < z.length; i++) z[i] = new Complex();
+ for (int i = 0; i < e.length; i++) e[i] = new Complex();
+ for (int i = 0; i < w.length; i++) w[i] = new Complex();
+ }
+
+// CHECKSTYLE.OFF: .*
+float Cos (float x) {
+/* computes cos of x (x in radians) by an expansion */
+int i, factor;
+float result, power;
+
+ result = 1.0f;
+ factor = 1;
+ power = x;
+ for ( i = 2; i <= 10; i++ ) {
+ factor = factor * i; power = power*x;
+ if ( (i & 1) == 0 ) {
+ if ( (i & 3) == 0 ) result = result + power/factor;
+ else result = result - power/factor;
+ }
+ }
+ return (result);
+}
+
+int Min0( int arg1, int arg2) {
+ if ( arg1 < arg2 ) return (arg1);
+ else return (arg2);
+}
+
+int Uniform11(int iy) {
+ return (4855 * iy + 1731) & 8191;
+} /* uniform */
+
+void Exptab(int n, Complex e[]) { /* exptab */
+ float theta, divisor;
+ int i, j, k, l, m;
+
+ theta = 3.1415926536f;
+ divisor = 4.0f;
+ for ( i=1; i <= 25; i++ ) {
+ h[i] = 1/(2*Cos( theta/divisor ));
+ divisor = divisor + divisor;
+ }
+
+ m = n / 2 ;
+ l = m / 2 ;
+ j = 1 ;
+ e[1].rp = 1.0f;
+ e[1].ip = 0.0f;
+ e[l+1].rp = 0.0f;
+ e[l+1].ip = 1.0f;
+ e[m+1].rp = -1.0f;
+ e[m+1].ip = 0.0f;
+
+ do {
+ i = l / 2 ;
+ k = i ;
+
+ do {
+ e[k+1].rp = h[j]*(e[k+i+1].rp+e[k-i+1].rp) ;
+ e[k+1].ip = h[j]*(e[k+i+1].ip+e[k-i+1].ip) ;
+ k = k+l ;
+ } while ( k <= m );
+
+ j = Min0( j+1, 25);
+ l = i ;
+ } while ( l > 1 );
+
+} /* exptab */
+
+void Fft( int n, Complex z[], Complex w[], Complex e[], float sqrinv) {
+ int i, j, k, l, m, index;
+ m = n / 2 ;
+ l = 1 ;
+
+ do {
+ k = 0 ;
+ j = l ;
+ i = 1 ;
+
+ do {
+
+ do {
+ w[i+k].rp = z[i].rp+z[m+i].rp ;
+ w[i+k].ip = z[i].ip+z[m+i].ip ;
+ w[i+j].rp = e[k+1].rp*(z[i].rp-z[i+m].rp)
+ -e[k+1].ip*(z[i].ip-z[i+m].ip) ;
+ w[i+j].ip = e[k+1].rp*(z[i].ip-z[i+m].ip)
+ +e[k+1].ip*(z[i].rp-z[i+m].rp) ;
+ i = i+1 ;
+ } while ( i <= j );
+
+ k = j ;
+ j = k+l ;
+ } while ( j <= m );
+
+ /*z = w ;*/ index = 1;
+ do {
+ z[index].rp = w[index].rp;
+ z[index].ip = w[index].ip;
+ index = index+1;
+ } while ( index <= n );
+ l = l+l ;
+ } while ( l <= m );
+
+ for ( i = 1; i <= n; i++ ){
+ z[i].rp = sqrinv*z[i].rp ;
+ z[i].ip = -sqrinv*z[i].ip;
+ }
+
+}
+
+void Oscar() { /* oscar */
+ int i;
+ Exptab(fftsize,e) ;
+ seed = 5767 ;
+ for ( i = 1; i <= fftsize; i++ ) {
+ seed = Uniform11( (int)seed ); /* typecast seed for 16 bit WR*/
+ zr = seed / 8192.0f;
+ seed = Uniform11( (int)seed ); /* typecast seed for 16 bit WR*/
+ zi = seed / 8192.0f;
+ z[i].rp = 20.0f*zr - 10.0f;
+ z[i].ip = 20.0f*zi - 10.0f;
+ }
+ for ( i = 1; i <= 20; i++ ) {
+ Fft(fftsize,z,w,e,0.0625f) ;
+ }
+} /* oscar */
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimeOscar() {
+ Oscar();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Perm.java b/src/main/java/org/linaro/benchmarks/stanford/Perm.java
new file mode 100644
index 0000000..1f04a58
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Perm.java
@@ -0,0 +1,68 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Perm {
+
+ private static final int permrange = 10;
+
+ private boolean error;
+
+ /* Perm */
+ private int[] permarray = new int [permrange + 1];
+ /* converted pctr to unsigned int for 16 bit WR*/
+ private int pctr;
+
+// CHECKSTYLE.OFF: .*
+ /* Permutation program, heavily recursive, written by Denny Brown. */
+void Swap ( int a[], int ai, int b[], int bi ) {
+ int t;
+ t = a[ai]; a[ai] = b[bi]; b[bi] = t;
+}
+
+void Initialize () {
+ int i;
+ for ( i = 1; i <= 7; i++ ) {
+ permarray[i]=i-1;
+ }
+}
+
+void Permute (int n) { /* permute */
+ int k;
+ pctr = pctr + 1;
+ if ( n!=1 ) {
+ Permute(n-1);
+ for ( k = n-1; k >= 1; k-- ) {
+ Swap(permarray, n, permarray, k);
+ Permute(n-1);
+ Swap(permarray, n, permarray, k);
+ }
+ }
+} /* permute */
+
+void Perm () { /* Perm */
+ int i;
+ pctr = 0;
+ for ( i = 1; i <= 5; i++ ) {
+ Initialize();
+ Permute(7);
+ }
+ if ( pctr != 43300 )
+ error = true;
+} /* Perm */
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimePerm() {
+ Perm();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Puzzle.java b/src/main/java/org/linaro/benchmarks/stanford/Puzzle.java
new file mode 100644
index 0000000..c9a142c
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Puzzle.java
@@ -0,0 +1,128 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Puzzle {
+
+ private static final int size = 511;
+ private static final int classmax = 3;
+ private static final int typemax = 12;
+ private static final int d = 8;
+
+ private int error = 0;
+
+ /* puzzle */
+ private int[] piececount = new int [classmax + 1];
+ private int[] cls = new int [typemax + 1];
+ private int[] piecemax = new int [typemax + 1];
+ private boolean[] puzzl = new boolean [size + 1];
+ private boolean[][] p = new boolean [typemax + 1][size + 1];
+ private int n;
+ private int kount;
+
+// CHECKSTYLE.OFF: .*
+boolean Fit (int i, int j) {
+ int k;
+ for ( k = 0; k <= piecemax[i]; k++ )
+ if ( p[i][k] ) if ( puzzl[j+k] ) return (false);
+ return (true);
+}
+
+int Place (int i, int j) {
+ int k;
+ for ( k = 0; k <= piecemax[i]; k++ ) if ( p[i][k] ) puzzl[j+k] = true;
+ piececount[cls[i]] = piececount[cls[i]] - 1;
+ for ( k = j; k <= size; k++ ) if ( ! puzzl[k] ) return (k);
+ return (0);
+}
+
+void Remove (int i, int j) {
+ int k;
+ for ( k = 0; k <= piecemax[i]; k++ ) if ( p[i][k] ) puzzl[j+k] = false;
+ piececount[cls[i]] = piececount[cls[i]] + 1;
+}
+
+boolean Trial (int j) {
+ int i, k;
+ kount = kount + 1;
+ for ( i = 0; i <= typemax; i++ )
+ if ( piececount[cls[i]] != 0 )
+ if ( Fit (i, j) ) {
+ k = Place (i, j);
+ if ( Trial(k) || (k == 0) )return (true);
+ else Remove (i, j);
+ }
+ return (false);
+}
+
+void Puzzle () {
+ int i, j, k, m;
+ for ( m = 0; m <= size; m++ ) puzzl[m] = true;
+ for( i = 1; i <= 5; i++ )for( j = 1; j <= 5; j++ )for( k = 1; k <= 5; k++ ) puzzl[i+d*(j+d*k)] = false;
+ for( i = 0; i <= typemax; i++ )for( m = 0; m<= size; m++ ) p[i][m] = false;
+ for( i = 0; i <= 3; i++ )for( j = 0; j <= 1; j++ )for( k = 0; k <= 0; k++ ) p[0][i+d*(j+d*k)] = true;
+ cls[0] = 0;
+ piecemax[0] = 3+d*1+d*d*0;
+ for( i = 0; i <= 1; i++ )for( j = 0; j <= 0; j++ )for( k = 0; k <= 3; k++ ) p[1][i+d*(j+d*k)] = true;
+ cls[1] = 0;
+ piecemax[1] = 1+d*0+d*d*3;
+ for( i = 0; i <= 0; i++ )for( j = 0; j <= 3; j++ )for( k = 0; k <= 1; k++ ) p[2][i+d*(j+d*k)] = true;
+ cls[2] = 0;
+ piecemax[2] = 0+d*3+d*d*1;
+ for( i = 0; i <= 1; i++ )for( j = 0; j <= 3; j++ )for( k = 0; k <= 0; k++ ) p[3][i+d*(j+d*k)] = true;
+ cls[3] = 0;
+ piecemax[3] = 1+d*3+d*d*0;
+ for( i = 0; i <= 3; i++ )for( j = 0; j <= 0; j++ )for( k = 0; k <= 1; k++ ) p[4][i+d*(j+d*k)] = true;
+ cls[4] = 0;
+ piecemax[4] = 3+d*0+d*d*1;
+ for( i = 0; i <= 0; i++ )for( j = 0; j <= 1; j++ )for( k = 0; k <= 3; k++ ) p[5][i+d*(j+d*k)] = true;
+ cls[5] = 0;
+ piecemax[5] = 0+d*1+d*d*3;
+ for( i = 0; i <= 2; i++ )for( j = 0; j <= 0; j++ )for( k = 0; k <= 0; k++ ) p[6][i+d*(j+d*k)] = true;
+ cls[6] = 1;
+ piecemax[6] = 2+d*0+d*d*0;
+ for( i = 0; i <= 0; i++ )for( j = 0; j <= 2; j++ )for( k = 0; k <= 0; k++ ) p[7][i+d*(j+d*k)] = true;
+ cls[7] = 1;
+ piecemax[7] = 0+d*2+d*d*0;
+ for( i = 0; i <= 0; i++ )for( j = 0; j <= 0; j++ )for( k = 0; k <= 2; k++ ) p[8][i+d*(j+d*k)] = true;
+ cls[8] = 1;
+ piecemax[8] = 0+d*0+d*d*2;
+ for( i = 0; i <= 1; i++ )for( j = 0; j <= 1; j++ )for( k = 0; k <= 0; k++ ) p[9][i+d*(j+d*k)] = true;
+ cls[9] = 2;
+ piecemax[9] = 1+d*1+d*d*0;
+ for( i = 0; i <= 1; i++ )for( j = 0; j <= 0; j++ )for( k = 0; k <= 1; k++ ) p[10][i+d*(j+d*k)] = true;
+ cls[10] = 2;
+ piecemax[10] = 1+d*0+d*d*1;
+ for( i = 0; i <= 0; i++ )for( j = 0; j <= 1; j++ )for( k = 0; k <= 1; k++ ) p[11][i+d*(j+d*k)] = true;
+ cls[11] = 2;
+ piecemax[11] = 0+d*1+d*d*1;
+ for( i = 0; i <= 1; i++ )for( j = 0; j <= 1; j++ )for( k = 0; k <= 1; k++ ) p[12][i+d*(j+d*k)] = true;
+ cls[12] = 3;
+ piecemax[12] = 1+d*1+d*d*1;
+ piececount[0] = 13;
+ piececount[1] = 3;
+ piececount[2] = 1;
+ piececount[3] = 1;
+ m = 1+d*(1+d*1);
+ kount = 0;
+ if ( Fit(0, m) ) n = Place(0, m);
+ else error = 1;
+ if ( ! Trial(n) ) error = 2;
+ else if ( kount != 2005 ) error = 3;
+}
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimePuzzle() {
+ Puzzle();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Queens.java b/src/main/java/org/linaro/benchmarks/stanford/Queens.java
new file mode 100644
index 0000000..2da9f04
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Queens.java
@@ -0,0 +1,80 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Queens {
+
+ /* Since the original benchmark uses these to calculate indices,
+ * it is not appropriate to use pure booleans, and we use the constants below:
+ */
+ private static final int FALSE = 0;
+ private static final int TRUE = 1;
+
+ private boolean error;
+ private int q = FALSE;
+
+ private int[] a = new int [9];
+ private int[] b = new int[17];
+ private int[] c = new int [15];
+ private int[] x = new int [9];
+
+// CHECKSTYLE.OFF: .*
+void Try(int i, int a[], int b[], int c[], int x[]) {
+ int j;
+ j = 0;
+ q = FALSE;
+ while ( (q == FALSE) && (j != 8) ) {
+ j = j + 1;
+ q = FALSE;
+ if ( b[j] != FALSE && a[i+j] != FALSE && c[i-j+7] != FALSE ) {
+ x[i] = j;
+ b[j] = FALSE;
+ a[i+j] = FALSE;
+ c[i-j+7] = FALSE;
+ if ( i < 8 ) {
+ Try(i+1,a,b,c,x);
+ if ( q ==FALSE ) {
+ b[j] = TRUE;
+ a[i+j] = TRUE;
+ c[i-j+7] = TRUE;
+ }
+ }
+ else q = TRUE;
+ }
+ }
+}
+
+void Doit () {
+ int i;
+ i = 0 - 7;
+ while ( i <= 16 ) {
+ if ( (i >= 1) && (i <= 8) ) a[i] = TRUE;
+ if ( i >= 2 ) b[i] = TRUE;
+ if ( i <= 7 ) c[i+7] = TRUE;
+ i = i + 1;
+ }
+
+ Try(1, b, a, c, x);
+ if ( q == FALSE ) error = true;
+}
+
+void Queens () {
+ int i;
+ for ( i = 1; i <= 50; i++ ) Doit();
+}
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimeQueens() {
+ Queens();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Quicksort.java b/src/main/java/org/linaro/benchmarks/stanford/Quicksort.java
new file mode 100644
index 0000000..2232926
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Quicksort.java
@@ -0,0 +1,87 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Quicksort {
+
+ /* Bubble, Quick */
+ private static final int sortelements = 5000;
+ private static final int srtelements = 500;
+
+ private boolean error;
+ long seed;
+
+ int[] sortlist = new int [sortelements + 1];
+ int biggest;
+ int littlest;
+ int inttop;
+
+// CHECKSTYLE.OFF: .*
+void Initrand () {
+ seed = 74755L; /* constant to long WR*/
+}
+
+int Rand () {
+ seed = (seed * 1309L + 13849L) & 65535L; /* constants to long WR*/
+ return( (int)seed ); /* typecast back to int WR*/
+}
+
+ /* Sorts an array using quicksort */
+void Initarr() {
+ int i; /* temp */
+ long temp; /* made temp a long for 16 bit WR*/
+ Initrand();
+ biggest = 0; littlest = 0;
+ for ( i = 1; i <= sortelements; i++ ) {
+ temp = Rand();
+ /* converted constants to long in next stmt, typecast back to int WR*/
+ sortlist[i] = (int)(temp - (temp/100000L)*100000L - 50000L);
+ if ( sortlist[i] > biggest ) biggest = sortlist[i];
+ else if ( sortlist[i] < littlest ) littlest = sortlist[i];
+ }
+}
+
+void Quicksort( int a[], int l, int r) {
+ /* quicksort the array A from start to finish */
+ int i,j,x,w;
+ i=l; j=r;
+ x=a[(l+r) / 2];
+ do {
+ while ( a[i]<x ) i = i+1;
+ while ( x<a[j] ) j = j-1;
+ if ( i<=j ) {
+ w = a[i];
+ a[i] = a[j];
+ a[j] = w;
+ i = i+1; j= j-1;
+ }
+ } while ( i<=j );
+ if ( l <j ) Quicksort(a,l,j);
+ if ( i<r ) Quicksort(a,i,r);
+}
+
+void Quick () {
+ Quicksort(sortlist,1,sortelements);
+ if ( (sortlist[1] != littlest) || (sortlist[sortelements] != biggest) ) error = true;
+}
+ // CHECKSTYLE.ON: .*
+
+ @Setup
+ public void setup() {
+ Initarr();
+ }
+
+ @Benchmark
+ public void jmhTimeQuicksort() {
+ Quick();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/RealMM.java b/src/main/java/org/linaro/benchmarks/stanford/RealMM.java
new file mode 100644
index 0000000..0f8e4fa
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/RealMM.java
@@ -0,0 +1,68 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class RealMM {
+
+ private static final int rowsize = 40;
+
+ private double[][] rma = new double [rowsize + 1][rowsize + 1];
+ private double[][] rmb = new double [rowsize + 1][rowsize + 1];
+ private double[][] rmr = new double [rowsize + 1][rowsize + 1];
+
+ long seed;
+
+// CHECKSTYLE.OFF: .*
+void Initrand () {
+ seed = 74755L; /* constant to long WR*/
+}
+
+int Rand () {
+ seed = (seed * 1309L + 13849L) & 65535L; /* constants to long WR*/
+ return( (int)seed ); /* typecast back to int WR*/
+}
+
+
+ /* Multiplies two real matrices. */
+
+void rInitmatrix ( double m[][] ) {
+ int temp, i, j;
+ for ( i = 1; i <= rowsize; i++ )
+ for ( j = 1; j <= rowsize; j++ ) {
+ temp = Rand();
+ m[i][j] = (double)(temp - (temp/120)*120 - 60)/3;
+ }
+}
+
+void rInnerproduct(double result[][], double a[][], double b[][], int row, int column) {
+ /* computes the inner product of A[row,*] and B[*,column] */
+ int i;
+ result[row][column] = 0.0f;
+ for (i = 1; i<=rowsize; i++) result[row][column] = result[row][column]+a[row][i]*b[i][column];
+}
+
+void Mm () {
+ int i, j;
+ Initrand();
+ rInitmatrix (rma);
+ rInitmatrix (rmb);
+ for ( i = 1; i <= rowsize; i++ )
+ for ( j = 1; j <= rowsize; j++ )
+ rInnerproduct(rmr,rma,rmb,i,j);
+}
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimeRealMM() {
+ Mm();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Towers.java b/src/main/java/org/linaro/benchmarks/stanford/Towers.java
new file mode 100644
index 0000000..0e57ea5
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Towers.java
@@ -0,0 +1,128 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Towers {
+
+ private static final int maxcells = 18;
+
+ private static final int stackrange = 3;
+
+ private boolean error;
+
+ class Element {
+ int discsize;
+ int next;
+ }
+
+ int[] stack = new int[stackrange + 1];
+ Element[] cellspace = new Element[maxcells + 1];
+ int freelist;
+ int movesdone;
+
+ public Towers() {
+ for (int i = 0; i < cellspace.length; i++) {
+ cellspace[i] = new Element();
+ }
+ }
+
+// CHECKSTYLE.OFF: .*
+void Error (String emsg){
+ error = true;
+}
+
+
+void Makenull (int s) {
+ stack[s]=0;
+}
+
+int Getelement () {
+ int temp = 0; /* force init of temp WR*/
+ if ( freelist>0 ) {
+ temp = freelist;
+ freelist = cellspace[freelist].next;
+ } else
+ Error("out of space ");
+ return (temp);
+}
+
+void Push(int i, int s) {
+ boolean errorfound=false;
+ int localel;
+ if ( stack[s] > 0 )
+ if ( cellspace[stack[s]].discsize<=i ) {
+ errorfound=true;
+ Error("disc size error");
+ }
+ if ( ! errorfound ) {
+ localel=Getelement();
+ cellspace[localel].next=stack[s];
+ stack[s]=localel;
+ cellspace[localel].discsize=i;
+ }
+}
+
+void Init (int s, int n) {
+ int discctr;
+ Makenull(s);
+ for ( discctr = n; discctr >= 1; discctr-- )
+ Push(discctr,s);
+}
+
+int Pop (int s) {
+ int temp, temp1;
+ if ( stack[s] > 0 ) {
+ temp1 = cellspace[stack[s]].discsize;
+ temp = cellspace[stack[s]].next;
+ cellspace[stack[s]].next=freelist;
+ freelist=stack[s];
+ stack[s]=temp;
+ return (temp1);
+ } else
+ Error("nothing to pop ");
+ return 0;
+}
+
+void Move (int s1, int s2) {
+ Push(Pop(s1),s2);
+ movesdone=movesdone+1;
+}
+
+void tower(int i, int j, int k) {
+ int other;
+ if ( k==1 ) Move(i,j);
+ else {
+ other=6-i-j;
+ tower(i,other,k-1);
+ Move(i,j);
+ tower(other,j,k-1);
+ }
+}
+
+void Towers () { /* Towers */
+ int i;
+ for ( i=1; i <= maxcells; i++ ) cellspace[i].next=i-1;
+ freelist=maxcells;
+ Init(1,14);
+ Makenull(2);
+ Makenull(3);
+ movesdone=0;
+ tower(1,2,14);
+ if ( movesdone != 16383 ) error = true;
+} /* Towers */
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimeTowers() {
+ Towers();
+ }
+}
diff --git a/src/main/java/org/linaro/benchmarks/stanford/Treesort.java b/src/main/java/org/linaro/benchmarks/stanford/Treesort.java
new file mode 100644
index 0000000..e044926
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/stanford/Treesort.java
@@ -0,0 +1,108 @@
+/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
+ * License: LLVM Release License. See Notice file
+ */
+
+package org.linaro.benchmarks.stanford;
+
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class Treesort {
+
+ private static final int sortelements = 5000;
+ private static final int srtelements = 500;
+
+ private boolean error;
+
+ private long seed;
+
+ private int[] sortlist = new int [sortelements + 1];
+ private int biggest;
+ private int littlest;
+ private int top;
+
+ class Node {
+ Node left;
+ Node right;
+ int val;
+ }
+
+ Node tree;
+
+// CHECKSTYLE.OFF: .*
+void Initrand () {
+ seed = 74755L; /* constant to long WR*/
+}
+
+int Rand () {
+ seed = (seed * 1309L + 13849L) & 65535L; /* constants to long WR*/
+ return( (int)seed ); /* typecast back to int WR*/
+}
+
+
+
+ /* Sorts an array using treesort */
+
+void tInitarr() {
+ int i;
+ long temp; /* converted temp to long for 16 bit WR*/
+ Initrand();
+ biggest = 0; littlest = 0;
+ for ( i = 1; i <= sortelements; i++ ) {
+ temp = Rand();
+ /* converted constants to long in next stmt, typecast back to int WR*/
+ sortlist[i] = (int)(temp - (temp/100000L)*100000L - 50000L);
+ if ( sortlist[i] > biggest ) biggest = sortlist[i];
+ else if ( sortlist[i] < littlest ) littlest = sortlist[i];
+ }
+}
+
+void CreateNode (Node t, int n) {
+ t = new Node();
+ t.val = n;
+}
+
+void Insert(int n, Node t) {
+ /* insert n into tree */
+ if ( n > t.val )
+ if ( t.left == null ) CreateNode(t.left,n);
+ else Insert(n,t.left);
+ else if ( n < t.val )
+ if ( t.right == null ) CreateNode(t.right,n);
+ else Insert(n,t.right);
+}
+
+
+boolean Checktree(Node p) {
+ /* check by inorder traversal */
+ boolean result;
+ result = true;
+ if ( p.left != null )
+ if ( p.left.val <= p.val ) result=false;
+ else result = Checktree(p.left) && result;
+ if ( p.right != null )
+ if ( p.right.val >= p.val ) result = false;
+ else result = Checktree(p.right) && result;
+ return( result);
+} /* checktree */
+
+void Trees() {
+ int i;
+ tInitarr();
+ tree = new Node();
+ tree.left = null; tree.right=null; tree.val=sortlist[1];
+ for ( i = 2; i <= sortelements; i++ )
+ Insert(sortlist[i],tree);
+ if ( ! Checktree(tree) ) error = true;
+}
+ // CHECKSTYLE.ON: .*
+
+ @Benchmark
+ public void jmhTimeTreesort() {
+ Trees();
+ }
+}