I have a function that retrieves the high and low order bits of the CPUs cycle-counter (Using GCC asm):

Code:
void access_counter(unsigned *hi, unsigned *lo) {
        asm("rdtsc; movl %%edx,%0; movl %%eax,%1"
        : "=r" (*hi), "=r" (*lo)
        :
        : "%edx", "%eax");
}
... And I am writing a function that returns a u_int64_t based on the high and low order bits of access_counter():

Code:
u_int64_t get_cycles(void) {
        unsigned hi, lo;
        u_int64_t hi_shift;

        access_counter(&hi, &lo);

        hi_shift = hi;

        return (hi_shift << 32) + lo;
}
... This seems like the correct way of doing this. The only problem is that I cannot think of a way to check if it is correct. So I was hoping someone could look this over and see if this correctly returns the value of the cycle counter as a u_int64_t.

Thanks