how can i calc the cycles per instruction?
i'm using rdtsc in the way below thare's something worng with it?

db 0fh,31h ;rdtsc
push eax

xor eax,eax
loop_eax:
inc eax
or eax,eax
jnz loop_eax

db 0fh,31h ;rdtsc
pop ebx
sub eax,ebx

;eax = cycles

i'm gotting 4340831 cycles is that right?
Posted on 2002-02-03 12:11:46 by uNdErX
First, rdtsc returns a 64 bit value in EDX EXA. You are seeing only the low 32 bits in EAX.

Second, you are doing the loop 4,294,967,296 times. Even in the best possible case, if the INC and the OR execute together in 1 clock, and the JNZ in another clock, that's 2 per loop iteration.

Finally, chances are good that Windows will interrupt a loop taking this long, perhaps several times, as part of normal task swithcing.

I suggest you do a search on RDTSC. There are several examples.

:)
Posted on 2002-02-03 14:38:46 by S/390
i understud what you say! thanks!
i write the correct way:

db 0fh,31h ;rdtsc
push eax edx

xor eax,eax
l:
inc eax
or eax,eax
jnz l

db 0fh,31h ;rdtsc
pop ebx ecx
sub eax,ecx
sub edx,ebx

;14.117.588.073
Posted on 2002-02-03 15:30:45 by uNdErX
uNdErX,

just be aware that RDTSC suffers from interference when run in ring3 in win32. The effect is that the accuracy is subject to variation of about 3 - 5 %.

If you can run the code for a half a second or so, it will bring the variation down to under 1 % which is acceptable in most instances for timing algorithms.

Regards,

hutch@movsd.com
Posted on 2002-02-03 15:45:34 by hutch--