1 // helpful utility and synch functions
3 // relies on defining "ncores" before including this file...
8 #include <machine/syscall.h>
10 #define rdcycle() ({ unsigned long _c; asm volatile ("rdcycle %0" : "=r"(_c) :: "memory"); _c; })
11 #define rdinstret() ({ unsigned long _c; asm volatile ("rdinstret %0" : "=r"(_c) :: "memory"); _c; })
13 void __attribute__((noinline
)) barrier()
15 static volatile int sense
;
16 static volatile int count
;
17 static __thread
int threadsense
;
21 threadsense
= !threadsense
;
22 if (__sync_fetch_and_add(&count
, 1) == ncores
-1)
27 else while(sense
!= threadsense
)
37 void finishTest(int test_result
)
40 if ( test_result
== 1 )
41 printf( "*** PASSED ***\n" );
43 printf( "*** FAILED *** (tohost = %d)\n", test_result
);
47 // perform exit syscall
54 "scall" : : "r"(test_result
) , "i"(SYS_exit
));