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
);
34 static void printArray(const char name
[], int n
, const int arr
[])
38 printf( " %10s :", name
);
39 for ( i
= 0; i
< n
; i
++ )
40 printf( " %3d ", arr
[i
] );
45 static void printDoubleArray(const char name
[], int n
, const double arr
[])
49 printf( " %10s :", name
);
50 for ( i
= 0; i
< n
; i
++ )
51 printf( " %g ", arr
[i
] );
56 static int verify(int n
, const volatile int* test
, const int* verify
)
59 // Unrolled for faster verification
60 for (i
= 0; i
< n
/2*2; i
+=2)
62 int t0
= test
[i
], t1
= test
[i
+1];
63 int v0
= verify
[i
], v1
= verify
[i
+1];
64 if (t0
!= v0
) return i
+1;
65 if (t1
!= v1
) return i
+2;
67 if (n
% 2 != 0 && test
[n
-1] != verify
[n
-1])
72 static int verifyDouble(int n
, const volatile double* test
, const double* verify
)
75 // Unrolled for faster verification
76 for (i
= 0; i
< n
/2*2; i
+=2)
78 double t0
= test
[i
], t1
= test
[i
+1];
79 double v0
= verify
[i
], v1
= verify
[i
+1];
80 int eq1
= t0
== v0
, eq2
= t1
== v1
;
81 if (!(eq1
& eq2
)) return i
+1+eq1
;
83 if (n
% 2 != 0 && test
[n
-1] != verify
[n
-1])
92 static void __attribute__((noinline
)) barrier()
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"