- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
{
__asm{
_emit 0x0f
_emit 0x31
lea ecx,tick
mov dword ptr [ecx], eax
mov dword ptr [ecx+4],edx
}
}
while (1) {
getTick();
printf("%I64u ", tick);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems not always work on Core Duo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want the same code to work in both 32- and 64-bit compilation, you should use the _rdtsc() intrinsic, supported by Intel and MS C++.
rdtsc works fine on Core 2 Duo, where it is based on the Front Side Bus clock. I do find that I must repeat a code over a longer time intervalto get repeatable timing on Core 2 than on earlier Intel architectures. My results are sufficiently repeatable for elapsed time intervals of 0.0001 seconds or more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using a 32bit WinXP Prof. on a Core Duo E6400, instead of 64bit OS. The code I am using to get clocktick is something like this:
unsigned __int64 GetCycleCount()
{
__asm_emit 0x0F
__asm_emit0x31
}
It does work on the PC, but not always work. And it seems has nothing to do with elapsed time. Say, it can measure a thread that run for less than 0.1ms, on the other hand, it gives 0 to a thread that may last more than 100ms. And the result is repeatable, which means the function always gives zero for some conditions. That is very weird.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks like you are seeing only the low order 32 bits of the timer registers. Aart's example shows you how to get all 64 bits in 32-bit asm. Compiling in 64-bit mode (should you change OS in the future), you need a different version to get 64 bits. With gcc compatible compilers, you need yet other variations. So, I repeat the suggestion of looking up __rdtsc() http://msdn2.microsoft.com/en-us/library/twchhe95(VS.80).aspx
if you are willing to use a compiler recent enough to support it. I think even the free Microsoft compilers from 2003 on include this intrinsic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page