Benchmarks now run in user-mode.
[riscv-tests.git] / benchmarks / common / util.h
index 83b2b6c4a1638b4262d86ed09427c38e884be5ed..79d9256a7060c0eedfd2919a2ee815e1155b65b5 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef __UTIL_H
 #define __UTIL_H
 
+#include <machine/syscall.h>
+
 #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; })
                             
@@ -27,6 +29,32 @@ 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   ;"
+          "syscall" : : "r"(test_result) , "i"(SYS_exit));
+   }
+#endif
+}
+
 #endif //__UTIL_H