在mips32中是这样实现的:
#define rdtscl(dest)\
__asm__ __volatile__("mfc0 %0, $9; nop":"=r"(dest));
但是我发现$9是一个32位的寄存器,那如何实现64位上电时间呢?
下面是一些其他体系结构的实现方法,实现的都是64位的,就是想在上面加上mips64的实现方法,请各位大牛们给予指点,万分感谢~
struct CycleClock {
// This should return the number of cycles since power-on. Thread-safe.
static inline int64 Now() {
#if defined(__MACH__) && defined(__APPLE__)
return mach_absolute_time();
#elif defined(__i386__)
int64 ret;
__asm__ volatile ("rdtsc" : "=A" (ret) );
return ret;
#elif defined(__x86_64__) || defined(__amd64__)
uint64 low, high;
__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
return (high << 32) | low;
#elif defined(__powerpc__) || defined(__ppc__)
// This returns a time-base, which is not always precisely a cycle-count.
int64 tbl, tbu0, tbu1;
asm("mftbu %0" : "=r" (tbu0));
asm("mftb %0" : "=r" (tbl));
asm("mftbu %0" : "=r" (tbu1));
tbl &= -static_cast<int64>(tbu0 == tbu1);
// high 32 bits in tbu1; low 32 bits in tbl (tbu0 is garbage)
return (tbu1 << 32) | tbl;