From: PerrimanSmythe <com...@ma...> - 2009-10-11 16:51:42
|
Gisle Vanem-2 wrote: > > "PerrimanSmythe" <com...@ma...> wrote: > >> The problem is, that when I'm reading the tsc value using the rdtsc >> instruction, I get only the lower 32 bits of timestamp. I've tried using >> different styles of calling the rdtsc I've found on the internet, but the >> problem persists. The current code I use is as follows: >> >> unsigned long long rdtsc() >> { >> unsigned long long temp; >> __asm__ __volatile__ >> ( >> "cpuid \n" >> "rdtsc \n" >> "leal %0, %%ecx \n" >> "movl %%eax, (%%ecx) \n" >> "movl %%edx, 4(%%ecx)" :: "m"(temp) : "eax", "ebx", "ecx", "edx" >> ); >> return temp; >> } > > Here is one I'm using with success for many years: > > /* > * Return CPU timestamp value. This code is originally by > * Tom Burgess <Tom...@bc...> and > * Douglas Eleveld <del...@dd...> > */ > extern __inline__ uint64 get_rdtsc (void) > { > register uint64 tsc; > __asm__ __volatile__ ( > ".byte 0x0F, 0x31;" /* rdtsc opcode */ > : "=A" (tsc) ); > return (tsc); > } > > > --gv > > Thank you for you reply. Unfortunately, it doesn't work this way either. I only get the lower 32 bits of tsc, and if my code runs for more than 2^32 cycles, and that's about 1.5 seconds, it overflows and I get wrong results. I also tried exactly the same code on the core 2 duo notebook with 32-bit Vista OS (this one is not the one I mentioned in first post) with the exactly same MinGW I have on my PC, and it works just fine! -- View this message in context: http://www.nabble.com/Trouble-with-rdtsc-on-amd64-in-32-bit-environment-tp25843286p25845204.html Sent from the MinGW - User mailing list archive at Nabble.com. |