![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2004
Posts: 7
Rep Power: 0
![]() |
I'm trying to use the RDTSC (Read Time-Stamp Counter) x86 instruction in my C program. Now I have the instruction working... but I want to take the entire 64-bits and divide them by 400,900,000 (400.9M) to convert the cps rate into seconds in a floating-point format of some type. Then I want to display these seconds in a string using the PRINTF function. Can anyone offer some example code of how I might do this? The fact that the time-stamp is 64-bits long is what keeps throwing me for a loop since I'm obviously programming on a 32-bit platform.
|
|
|
|
|
|
#2 |
|
Newbie
Join Date: Dec 2004
Posts: 7
Rep Power: 0
![]() |
Re:
This comes from Ken Silverman:
#if 0 //To compile, type: "nmake getmhz.c"
getmhz.exe: getmhz.c; cl getmhz.c /MD /G6y /Ox /nologo /link /opt:nowin98
!if 0
#endif
#include <windows.h>
#include <stdio.h>
static __forceinline __int64 rdtsc64 () { _asm rdtsc }
void main ()
{
__int64 q0, q1, t0, t1, qfrq;
QueryPerformanceFrequency((LARGE_INTEGER *)&qfrq);
QueryPerformanceCounter((LARGE_INTEGER *)&q0);
t0 = rdtsc64();
while (1) //Force at least a 1/32 second delay (use longer for more accuracy)
{
QueryPerformanceCounter((LARGE_INTEGER *)&q1);
if (q1-q0 >= (qfrq>>5)) break;
}
QueryPerformanceCounter((LARGE_INTEGER *)&q1);
t1 = rdtsc64();
printf("Detected frequency: %.0fhz",((double)qfrq) * ((double)(t1-t0)) / ((double)(q1-q0)));
getch();
}
#if 0
!endif
#endifProblem solved. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|