well i have this code i assembled in place in olly it works as expected and produces results as expected
now i have these results
0000000C --- edx timer hi
8E14DCED --- eax timer lo
00000020 --- edi so it pushed 8 results

so my problem is how do i calculate how much cycles this proc took
in irc i got a reply saying that the amount of cycles it took is ==
edx*2^32+eax is it right

if it is right what time it took to clock this much cycle some one told me to divide this cycle by my processor speed
but i dont see how can i find my processer speed programatically
i tried cpuid but i dont think i can see the processor speed
destop--->mycomputer-->properties dont show my processor speed
start --settings --control panel--systeminfo does not have it
"" --->tools directx diagnostics does not have this figure
i can only see it when i reboot ---- it is 633 Mhz
any ideas how to find this speed programmatically and use it say this proc took
hope i make some sense with this question




PUSH EBP ; creating a stack frame
MOV EBP, ESP ; equalling stack top and stack bottom
RDTSC ; read date time stamp counter
MOV ESI, EAX ; move timer.lo to esi
MOV EDI, EDX ; move time.hi to edi
XOR ECX, ECX ; clearing ecx
MOV EAX, ECX ; eax will be whatever ecx is now for first time it is 0
SHL EAX, 2 ; some shit stuff i need to calculate
SHR EAX, 3 ; some shit stuff i need to calculate
RCR EAX, 1 ; some shit stuff i need to calculate
ADD EAX, 0FEDA ; some shit stuff i need to calculate
CMP EAX, 0B53FAC9 ; some shit stuff i need to calculate
JE SHORT <odbgload.result> ; compare here and if equal it jumps to result
INC ECX ; counter increased
CMP ECX, -1 ; test for 0ffffffffh (-1) to take care of 2^32
JE SHORT <odbgload.end> ; if 2^32 iteration compleated it jumps to end
JMP SHORT <odbgload.restart> ; else goes on to restart
PUSH ECX ; result here it pushes the ecx values when the first cmp were equal
JMP SHORT <odbgload.continue> ; continues iteratin till 2^32
RDTSC ; read date time stamp counter
SUB EAX, ESI ; latest timer.lo - original timer.lo
SUB EDX, EDI ; latest timer.hi - original timer.hi
MOV ESI, ESP ; saving esp some wher
MOV EDI, EBP ; saving ebp some where
SUB EDI, ESI ; subtracting the saved stack bot- stack top to find how many pushes have happened in this proc)
JMP SHORT odbgload.00401102 ; infinite jump so it doesnt crash as this code is jugglery of sorts
Posted on 2004-02-13 00:08:33 by bluffer
The clockspeed is stored in the Windows registry somewhere.
Alternatively you can clock it yourself.
store rdtsc, wait x seconds, subtract new rdtsc from stored rdtsc, and you have the nr of cycles in x seconds. Divide by x and you have the clockspeed.
You don't need the clockspeed in order to know how many cycles it took though :)
Note also that the nr of clks the routine takes may vary on different processors. And it may also vary on the same machine, if you are multitasking.
Posted on 2004-02-13 05:16:40 by Henk-Jan
Reading from the registry is probably the most reliable way of finding the clock speed of your CPU. Alternatively, boost process+thread priority to realtime, rdtsc, Sleep(250), rdtsc...
Posted on 2004-02-13 06:05:47 by f0dder
tx henk and fodder for reply

oops did i leave that info while posting
my registry doesnt have it ;) fodder
see this
REGEDIT4


"VendorIdentifier"="GenuineIntel"
"Identifier"="Intel(r) Celeron(tm) Processor"
"Update Status"=dword:00000007

so the question now remains is like this

RDTSC
MOV ESI, EAX
MOV EDI, EDX
****
my stuff ;esi and edi dont change here
****
RDTSC
SUB EAX, ESI <------- is this right i mean i am deducting old rdtsc lo from new
SUB EDX, EDI <------- is this right i mean i am deducting old rdtsc hi from new

edcba said i shoul use sbb should i use it if yes why if no why ;)

without sbb but with sub
i have these results

0000000C --- edx timer hi
8E14DCED --- eax timer lo

so how many cycles is this

is it 0xc*2^32 + 0x8e14dced == 53923339501 cycles ( i used calc.exe)

if it is right

now to calculte what time it took to do so much cycles

you suggest this way

rdtsc --->sleep 250 ---> rdtsc
( i dont know what boost process is ,i cant use set thread priority coz i am assembling this in place and i dont have that import)
ill get some value in eax:edx

so i should do (( (edx^32+eax)/250)*1000) -->no of cycles/second

so time it took in seconds for my proc == (my cycles/above mentioned value)

am i right

regards and thanks
Posted on 2004-02-13 07:09:28 by bluffer
You should use sbb yes, because the first sub (lowword) might have to borrow a bit from the highword, and sbb will correct the highword for that (if the bit was borrowed, carry was set, and sbb will subtract carry from the highword).
It's like add/adc if you are familiar with that.

I suggest this btw:

Sleep(0)
rdtsc
Sleep(x)
rdtsc

The first sleep will 'yield', as it's called, basically it means that you give up the remainder of the timeslice, and you let the OS run the other tasks. This way you are absolutely sure that the rdtsc and the Sleep(x) will be in the same timeslice (the new timeslice starts directly after the Sleep(0)), so you won't get any bad measurements.
For x you should take a value that works well enough for you, I think 1000 milliseconds generally works fine... That's what I use anyway. Should work fine even when not changing the thread priority, in most cases anyway.
Posted on 2004-02-13 12:24:24 by Henk-Jan
tx henk

k so iuse sbb when i have to subtract the low word (k it will borrow it like subtractin 9 from 17 one cant subrtact 9 from seven so it borrows k i got it)
but why should i do it for timer hi too

apart from that is my calculation (edx*2^32+eax) right
and the subsequent calculation is right assuming i use 250 ms for sleep
Posted on 2004-02-13 12:40:15 by bluffer
No, you do the sbb for the highword, and a regular sub for the lowword.
The sub will always borrow if required, and set carry if it does.
sbb will correct the borrow. It also sets carry if it has to borrow again, so you can do larger numbers aswell.
You always start with one add/sub, and then as many adc/sbb as you need.
Posted on 2004-02-13 14:18:32 by Henk-Jan