TSC Problem

TSC Problem

Ciao,

I have a strange situation on my systems with Intel Celeron M 600MHz processor.

In my routine I must calculate the elapsed time between an operation and another.

...

LARGE_INTEGER ini, fin, delta;

ini.QuadPart=RDTSC();

WorkDuringEverAbout15000tick();

fin.QuadPart=RDTSC();

delta.QuadPart=fin.QuadPart-ini.QuadPart;

...

I Use my RDTSC function for calculate delta time:

__inline __int64 RDTSC()

{

LARGE_INTEGER lint;

__asm {

push eax

push edx

_emit 0x0F ;RDTSC - get beginning timestamp to edx:eax

_emit 0x31

mov lint.HighPart,edx ;save beginning timestamp (1 cycle)

mov lint.LowPart,eax

pop edx

pop eax

}

return lint.QuadPart;

}

...where...

typedef union _LARGE_INTEGER {

struct {

DWORD LowPart;

LONG HighPart;

};

struct {

DWORD LowPart;

LONG HighPart;

} u;

__int64 QuadPart;

} LARGE_INTEGER;

almost always the delta time returned is exactly about 15000 but in one case at day I catch about 4294979655.

Now I've changed the code as below:

...

LARGE_INTEGER ini, fin, delta;

ini.QuadPart=RDTSC();

WorkDuringEverAbout15000tick();

fin.QuadPart=RDTSC();

delta.QuadPart=fin.QuadPart-ini.QuadPart;

if(delta.QuadPart>20000)

printf("ini[0x%.8X-0x%.8X] fin[0x%.8X-0x%.8X]\n", ini.HighPart, ini.LowPart, fin.HighPart, fin.LowPart);

...

I see on the video:

ini[0x00000005-0xFFFFCFB6] fin[0x00000006-0xFFFFFFFD]

It is as if the photograph of the upper part is made one second after that of the lower...isn't it?

Or I've made a mistake???

Regards

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.