1 // See LICENSE for license details.
6 extern void setStats(int enable
);
10 #define static_assert(cond) switch(0) { case 0: case !!(long)(cond): ; }
12 static int verify(int n
, const volatile int* test
, const int* verify
)
15 // Unrolled for faster verification
16 for (i
= 0; i
< n
/2*2; i
+=2)
18 int t0
= test
[i
], t1
= test
[i
+1];
19 int v0
= verify
[i
], v1
= verify
[i
+1];
20 if (t0
!= v0
) return i
+1;
21 if (t1
!= v1
) return i
+2;
23 if (n
% 2 != 0 && test
[n
-1] != verify
[n
-1])
28 static int verifyDouble(int n
, const volatile double* test
, const double* verify
)
31 // Unrolled for faster verification
32 for (i
= 0; i
< n
/2*2; i
+=2)
34 double t0
= test
[i
], t1
= test
[i
+1];
35 double v0
= verify
[i
], v1
= verify
[i
+1];
36 int eq1
= t0
== v0
, eq2
= t1
== v1
;
37 if (!(eq1
& eq2
)) return i
+1+eq1
;
39 if (n
% 2 != 0 && test
[n
-1] != verify
[n
-1])
44 static void __attribute__((noinline
)) barrier(int ncores
)
46 static volatile int sense
;
47 static volatile int count
;
48 static __thread
int threadsense
;
52 threadsense
= !threadsense
;
53 if (__sync_fetch_and_add(&count
, 1) == ncores
-1)
58 else while(sense
!= threadsense
)
64 static uint64_t lfsr(uint64_t x
)
66 uint64_t bit
= (x
^ (x
>> 1)) & 1;
67 return (x
>> 1) | (bit
<< 62);
70 static uintptr_t insn_len(uintptr_t pc
)
72 return (*(unsigned short*)pc
& 3) ? 4 : 2;
79 #define stringify_1(s) #s
80 #define stringify(s) stringify_1(s)
81 #define stats(code, iter) do { \
82 unsigned long _c = -read_csr(mcycle), _i = -read_csr(minstret); \
84 _c += read_csr(mcycle), _i += read_csr(minstret); \
86 printf("\n%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
87 stringify(code), _c, _c/iter, 10*_c/iter%10, _c/_i, 10*_c/_i%10); \