clock_cycle.h 820 Bytes
Newer Older
lwc-tester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#ifndef CLOCK_CYCLE_H
#define CLOCK_CYCLE_H

typedef unsigned long long int u64;

u64 start_rdtsc( )
{
        unsigned high, low;
        
        __asm__ volatile("CPUID\n\t"
                         "RDTSC\n\t"
                         "mov %%edx, %0\n\t"
                         "mov %%eax, %1\n\t": "=r" (high),
                         "=r" (low):: "%rax", "%rbx", "%rcx", "%rdx");
        return ( ((u64)low) | (((u64)high) << 32));
}

u64 end_rdtsc( )
{
        unsigned high, low;
        
        __asm__ volatile("RDTSCP\n\t"
                         "mov %%edx, %0\n\t"
                         "mov %%eax,%1\n\t"
                         "CPUID\n\t": "=r" (high), "=r" (low)::
                         "%rax", "%rbx", "%rcx", "%rdx");
        
        return ( ((u64)low) | (((u64)high) << 32));
}

#endif