summaryrefslogtreecommitdiff
path: root/src/main/java/org/linaro/benchmarks/stanford/Queens.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/stanford/Queens.java')
-rw-r--r--src/main/java/org/linaro/benchmarks/stanford/Queens.java80
1 files changed, 80 insertions, 0 deletions
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();
+ }
+}