Originally Posted by
swoopy
Using what Salem posted, I think this gives you the 64-bit value:
Code:
/* Get current value of cycle counter */
access_counter(&ncyc_hi, &ncyc_lo);
result = ncyc_hi;
result <<= 32;
result += ncyc_lo;
return result;
You can also create two 64-bit temps (as shown above), and do it in fewer steps. But I believe the problem is the print statement. I don't believe the following prints the 64-bit value correctly:
Code:
printf("elapsed: %llu\n", end - start);
At least on my computer, using Dev-C++, it only prints 32-bits. I don't know how you print 64-bits.
With gcc on my Windows XP box this works:
Code:
#include <stdio.h>
#include <sys/types.h>
/*
* just in case you want a function to hide the bit shifting
*/
u_int64_t make_longlong(u_int32_t, u_int32_t);
int main ()
{
u_int64_t start, end, diff;
u_int32_t hi, lo;
hi = 0x12345678;
lo = 0x9abcdef0;
start = make_longlong(hi, lo);
hi = 0x55555555;
lo = 0x11111111;
end = ((u_int64_t)hi << 32) | lo;
diff = end - start;
printf("end = %llu (%llx hex)\n", end, end);
printf("start = %llu (%llx hex)\n", start, start);
printf("diff = %llu (%llx hex)\n", diff, diff);
return 0;
}
/* if you want to make a function to hide the bit shifting
* here's a possibility
*/
u_int64_t make_longlong(u_int32_t hi, u_int32_t lo)
{
return ((u_int64_t)hi << 32) | lo;
}
(If you run gcc -pedantic, it mentions that ISO C90 does not support the 'll' printf modifier.)
Regards,
Dave