code timing , whats wrong ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

code timing , whats wrong ?

Post by kmtdk »

well
i have tryed to time my code, using the RDTSC instrcution
but each time i use the instruction, Extreamly many cycles have passed since the last time,
and i dont have any code in betewen

the source is attached ( it is compiled as a "com" program, i have tryed on os, no change)
the time keeps changeing, but the difference is far too high.

Kmt dk
Attachments
test.asm
the source file
(1.29 KiB) Downloaded 99 times
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: code timing , whats wrong ?

Post by Combuster »

This looks wrong:

Code: Select all

mov [si],eax
mov [si+2],edx
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: code timing , whats wrong ?

Post by kmtdk »

the code stores the 64 bit integer at the variable ( i use si to point)
but have i done it reverse , so edx shuld be the first , and then eax.??


KMt dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: code timing , whats wrong ?

Post by djmauretto »

Did you mean:

Code: Select all

mov [si],eax
mov [si+4],edx
:wink:
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: code timing , whats wrong ?

Post by Masterkiller »

it returns EDX:EAX, so EAX store less-significant bytes and they are 32-bit = 4 bytes, you store them between two bytes so rewrite the EAX. In the memory less-significant bytes are stored in lower addresses.

Edit: Lower address is the address that you do not add offset (since the offset is positive). EAX is less-significant, so it should be stored at lower address e.g. [si+0], not [si+4] :)
Last edited by Masterkiller on Tue Nov 18, 2008 8:19 am, edited 2 times in total.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: code timing , whats wrong ?

Post by kmtdk »

* DOH
i forgot i was using 32 bit instructions, so that was one Big error.( the reason is i have worked on 16 bit too much ... )
so the code shuld look like this:

Code: Select all

mov [si],edx
mov [si+4],eax
I will just test it ( and if i dont post/ edit, it means that i dont have tryed it..)

KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: code timing , whats wrong ?

Post by djmauretto »

kmtdk wrote:* DOH
i forgot i was using 32 bit instructions, so that was one Big error.( the reason is i have worked on 16 bit too much ... )
so the code shuld look like this:

Code: Select all

mov [si],edx
mov [si+4],eax
I will just test it ( and if i dont post/ edit, it means that i dont have tryed it..)

KMT dk
[-X

Code: Select all

mov [si],eax
mov [si+4],edx
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: code timing , whats wrong ?

Post by kmtdk »

Well
now i got it to work, but one thing shuld be told
this does not work 100 % under windows, but it does ( it counts wierd), but you can see a different
the code is attached , and use it as you want, but if you want to publise the code, ask for permission.
bye the way, the code is Not optimised .

happy timing ,:P

KMT dk
Attachments
test.asm
The timing file, see inside where to place code to test.
(3.46 KiB) Downloaded 96 times
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: code timing , whats wrong ?

Post by Combuster »

I expect the TSC to jump large amounts when the OS decides to yield the CPU to another process. Also, unsynchronized counters can cause strange effects (going back in time, anyone?) when windows tosses the application between cores (windows' CPU affinity sucks big time, try forcing applications onto a single core and see whether it works better)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply