Files
wmaker/wrlib/bench.h
T

69 lines
1.5 KiB
C
Raw Normal View History

2000-01-14 23:37:20 +00:00
inline static void
2004-10-12 21:28:27 +00:00
cycle_bench(int start)
2000-01-14 23:37:20 +00:00
{
static volatile unsigned int start_cycle;
2000-01-21 21:04:20 +00:00
2000-01-14 23:37:20 +00:00
if (start) {
2004-10-12 21:28:27 +00:00
asm volatile
("pushl %%edx \n\t"
"rdtsc \n\t"
"movl %%eax,%0 \n\t"
"cld \n\t"
"popl %%edx \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
: "=m" (start_cycle) : : "eax", "edx");
2000-01-14 23:37:20 +00:00
} else {
2004-10-12 21:28:27 +00:00
volatile int end;
2000-01-21 21:04:20 +00:00
2004-10-12 21:28:27 +00:00
asm volatile
("pushl %%edx \n\t"
"clc \n\t"
"rdtsc \n\t"
"movl %%eax, %0 \n\t"
"popl %%edx \n\t"
: "=m" (end) : : "eax", "edx");
printf("Cycle count = %u\n", end - start_cycle - 68);
2000-01-14 23:37:20 +00:00
}
}
#if 0
// seems linux doesnt allow user progs to exec rdpcm..
inline static void
2004-10-12 21:28:27 +00:00
cache_bench(int start)
2000-01-14 23:37:20 +00:00
{
static int start_cycle;
2004-10-12 21:28:27 +00:00
2000-01-14 23:37:20 +00:00
if (start) {
2004-10-12 21:28:27 +00:00
asm volatile
("movl $1,%%ecx \n\t"
"rdpmc \n\t"
"movl %%eax,%0 \n\t"
: "=m" (start_cycle));
2000-01-14 23:37:20 +00:00
} else {
2004-10-12 21:28:27 +00:00
int end;
asm volatile
("movl $1,%%ecx \n\t"
"rdpmc \n\t"
"movl %%eax,%0"
: "=m" (end));
printf("Cache reloads counted = %i\n", end - start_cycle);
2000-01-14 23:37:20 +00:00
}
}
#endif