aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/common/util.h
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@eecs.berkeley.edu>2014-02-06 01:36:26 -0800
committerAndrew Waterman <waterman@eecs.berkeley.edu>2014-02-06 01:36:26 -0800
commit71330800b89cb4c6ae8716a7e78bdcf574fe04ab (patch)
tree5395bdf46cccee8f6c94538b63ab161fa41648db /benchmarks/common/util.h
parent6fdd12c130d0c0c13934364a4dfe12d8dcf28e27 (diff)
downloadriscv-tests-71330800b89cb4c6ae8716a7e78bdcf574fe04ab.zip
riscv-tests-71330800b89cb4c6ae8716a7e78bdcf574fe04ab.tar.gz
riscv-tests-71330800b89cb4c6ae8716a7e78bdcf574fe04ab.tar.bz2
Clean up benchmarks; support uarch-specific counters
Diffstat (limited to 'benchmarks/common/util.h')
-rw-r--r--benchmarks/common/util.h128
1 files changed, 94 insertions, 34 deletions
diff --git a/benchmarks/common/util.h b/benchmarks/common/util.h
index 10f3169..1f0c73c 100644
--- a/benchmarks/common/util.h
+++ b/benchmarks/common/util.h
@@ -1,16 +1,99 @@
-// helpful utility and synch functions
-
-// relies on defining "ncores" before including this file...
-
#ifndef __UTIL_H
#define __UTIL_H
-#include <machine/syscall.h>
+//--------------------------------------------------------------------------
+// Macros
+
+// Set HOST_DEBUG to 1 if you are going to compile this for a host
+// machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
+// to 0 if you are compiling with the smips-gcc toolchain.
+
+#ifndef HOST_DEBUG
+#define HOST_DEBUG 0
+#endif
+
+// Set PREALLOCATE to 1 if you want to preallocate the benchmark
+// function before starting stats. If you have instruction/data
+// caches and you don't want to count the overhead of misses, then
+// you will need to use preallocation.
+
+#ifndef PREALLOCATE
+#define PREALLOCATE 0
+#endif
+
+// Set SET_STATS to 1 if you want to carve out the piece that actually
+// does the computation.
+
+#ifndef SET_STATS
+#define SET_STATS 0
+#endif
+
+#if HOST_DEBUG
+#include <stdio.h>
+static void setStats(int enable) {}
+#else
+extern void setStats(int enable);
+#endif
+
+static void printArray(const char name[], int n, const int arr[])
+{
+#if HOST_DEBUG
+ int i;
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3d ", arr[i] );
+ printf( "\n" );
+#endif
+}
+
+static void printDoubleArray(const char name[], int n, const double arr[])
+{
+#if HOST_DEBUG
+ int i;
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %g ", arr[i] );
+ printf( "\n" );
+#endif
+}
+
+static int verify(int n, const int test[], const int verify[])
+{
+ int i;
+ // Unrolled for faster verification
+ for (i = 0; i < n/2*2; i+=2)
+ {
+ int t0 = test[i], t1 = test[i+1];
+ int v0 = verify[i], v1 = verify[i+1];
+ if (t0 != v0) return i+1;
+ if (t1 != v1) return i+2;
+ }
+ if (n % 2 != 0 && test[n-1] != verify[n-1])
+ return n;
+ return 0;
+}
-#define rdcycle() ({ unsigned long _c; asm volatile ("rdcycle %0" : "=r"(_c) :: "memory"); _c; })
-#define rdinstret() ({ unsigned long _c; asm volatile ("rdinstret %0" : "=r"(_c) :: "memory"); _c; })
-
-void __attribute__((noinline)) barrier()
+static int verifyDouble(int n, const double test[], const double verify[])
+{
+ int i;
+ // Unrolled for faster verification
+ for (i = 0; i < n/2*2; i+=2)
+ {
+ double t0 = test[i], t1 = test[i+1];
+ double v0 = verify[i], v1 = verify[i+1];
+ int eq1 = t0 == v0, eq2 = t1 == v1;
+ if (!(eq1 & eq2)) return i+1+eq1;
+ }
+ if (n % 2 != 0 && test[n-1] != verify[n-1])
+ return n;
+ return 0;
+}
+
+#ifndef ncores
+#define ncores 1
+#endif
+
+static void __attribute__((noinline)) barrier()
{
static volatile int sense;
static volatile int count;
@@ -30,31 +113,8 @@ void __attribute__((noinline)) barrier()
__sync_synchronize();
}
-
-
-
-
-void finishTest(int test_result)
-{
-#if HOST_DEBUG
- if ( test_result == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", test_result);
- exit(0);
-#else
- {
- // perform exit syscall
- asm volatile(
- "move a0,%0 ;"
- "li a1,0 ;"
- "li a2,0 ;"
- "li a3,0 ;"
- "li v0,%1 ;"
- "scall" : : "r"(test_result) , "i"(SYS_exit));
- }
+#ifdef __riscv
+#include "encoding.h"
#endif
-}
#endif //__UTIL_H
-