4 //--------------------------------------------------------------------------
7 // Set HOST_DEBUG to 1 if you are going to compile this for a host
8 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
9 // to 0 if you are compiling with the smips-gcc toolchain.
15 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
16 // function before starting stats. If you have instruction/data
17 // caches and you don't want to count the overhead of misses, then
18 // you will need to use preallocation.
24 // Set SET_STATS to 1 if you want to carve out the piece that actually
25 // does the computation.
29 static void setStats(int enable
) {}
31 extern void setStats(int enable
);
36 #define static_assert(cond) switch(0) { case 0: case !!(long)(cond): ; }
38 static void printArray(const char name
[], int n
, const int arr
[])
42 printf( " %10s :", name
);
43 for ( i
= 0; i
< n
; i
++ )
44 printf( " %3d ", arr
[i
] );
49 static void printDoubleArray(const char name
[], int n
, const double arr
[])
53 printf( " %10s :", name
);
54 for ( i
= 0; i
< n
; i
++ )
55 printf( " %g ", arr
[i
] );
60 static int verify(int n
, const volatile int* test
, const int* verify
)
63 // Unrolled for faster verification
64 for (i
= 0; i
< n
/2*2; i
+=2)
66 int t0
= test
[i
], t1
= test
[i
+1];
67 int v0
= verify
[i
], v1
= verify
[i
+1];
68 if (t0
!= v0
) return i
+1;
69 if (t1
!= v1
) return i
+2;
71 if (n
% 2 != 0 && test
[n
-1] != verify
[n
-1])
76 static int verifyDouble(int n
, const volatile double* test
, const double* verify
)
79 // Unrolled for faster verification
80 for (i
= 0; i
< n
/2*2; i
+=2)
82 double t0
= test
[i
], t1
= test
[i
+1];
83 double v0
= verify
[i
], v1
= verify
[i
+1];
84 int eq1
= t0
== v0
, eq2
= t1
== v1
;
85 if (!(eq1
& eq2
)) return i
+1+eq1
;
87 if (n
% 2 != 0 && test
[n
-1] != verify
[n
-1])
92 static void __attribute__((noinline
)) barrier(int ncores
)
94 static volatile int sense
;
95 static volatile int count
;
96 static __thread
int threadsense
;
100 threadsense
= !threadsense
;
101 if (__sync_fetch_and_add(&count
, 1) == ncores
-1)
106 else while(sense
!= threadsense
)
109 __sync_synchronize();
113 #include "encoding.h"
116 #define stringify_1(s) #s
117 #define stringify(s) stringify_1(s)
118 #define stats(code, iter) do { \
119 unsigned long _c = -rdcycle(), _i = -rdinstret(); \
121 _c += rdcycle(), _i += rdinstret(); \
123 printf("\n%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
124 stringify(code), _c, _c/iter, 10*_c/iter%10, _c/_i, 10*_c/_i%10); \