flat assembler
Message board for the users of flat assembler.
Index
> Main > emulating delay? |
Author |
|
HaHaAnonymous 19 Jan 2013, 15:59
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:57; edited 1 time in total |
|||
19 Jan 2013, 15:59 |
|
Overflowz 19 Jan 2013, 16:05
I know that it's in EDX:EAX, I need only low order cause I'm not doing it on bigger number delays. Then how?
|
|||
19 Jan 2013, 16:05 |
|
HaHaAnonymous 19 Jan 2013, 18:12
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:57; edited 1 time in total |
|||
19 Jan 2013, 18:12 |
|
baldr 19 Jan 2013, 18:45
Overflowz,
Do you want to pause program for an exact amount of time (that'll require real-time OS), or to stall execution (on a non-HT/multicore CPU) for the very same time (at least)? |
|||
19 Jan 2013, 18:45 |
|
cod3b453 19 Jan 2013, 21:09
The first section of code may have fewer ticks due to lower clock inside the sleep call than the second section which will likely max the core. This also assumes loop takes one clock per instruction cycle.
Without OS calls, the best I can think of is measure a small loop and scale it against your own real time readings, with checks on rdtsc for each loop iteration until the expected count has been reached. |
|||
19 Jan 2013, 21:09 |
|
f0dder 19 Jan 2013, 21:21
Overflowz wrote: Hi there, I'm thinking how to delay programs execution w/o using any API function that any OS provide. What's your reason for wanting to do it this way? Your OS has the advantage of simply not scheduling your thread for execution - which means zero CPU time wasted until it's back on the ready-list. If you try to do a delay by looping/whatever, you'll be burning a lot of CPU cycles, which is quite counter-productive. If you're trying to do this because you need very precise delays (which Sleep() doesn't give, although ), you're Doing Things Wrong and perhaps even using a wrong OS for your task _________________ - carpe noctem |
|||
19 Jan 2013, 21:21 |
|
SeproMan 20 Jan 2013, 11:13
Overflowz,
a. Are you sure that Windows allows the use of the "rdtsc" instruction? b. You do need the high dword EDX of the TSC because todays computers reach it easily. c. When you "sub eax,ebx" you might get a negative value! _________________ Real Address Mode. |
|||
20 Jan 2013, 11:13 |
|
f0dder 20 Jan 2013, 13:51
SeproMan wrote: a. Are you sure that Windows allows the use of the "rdtsc" instruction? It does - but it's not a good idea to use RDTSC for delay loops. On several AMD CPUs, the TSC is not synchronized between cores, which will give funny effects when your thread is rescheduled... and not all CPUs have a constant frequency for the TSC (because of frequency regulation). _________________ - carpe noctem |
|||
20 Jan 2013, 13:51 |
|
Overflowz 20 Jan 2013, 16:18
Sorry for long reply, I'm just curious how to pause execution of program for amount of time. I just want to know it deeper, how it can be done, or like a challenge which I can't solve
|
|||
20 Jan 2013, 16:18 |
|
ACP 23 Jan 2013, 07:35
If you still want to use rdtsc here is the proper way of calling it for time measurement:
Code: cpuid rdtsc ;rest of the code It will not solve some problems mentioned already however. |
|||
23 Jan 2013, 07:35 |
|
Overflowz 24 Jan 2013, 18:30
Should I believe that nobody have tried it yet?
|
|||
24 Jan 2013, 18:30 |
|
macgub 25 Jan 2013, 11:00
Overflowz,
have you tried it in other OS than Windows ? |
|||
25 Jan 2013, 11:00 |
|
Madis731 25 Jan 2013, 12:33
For example this:
Code: rdtsc ;get tick count shl rdx,32 add rdx,rax push rdx invoke Sleep, 1000 ;sleep for 1 seconds rdtsc shl rdx,32 add rax,rdx pop rdx sub rax,rdx mov rcx,rax loop $ ;each loop might take more than 1 tick (its a macroinstruction) takes about 5 seconds. Code: ; [---] @@: sub rcx,1 jne @b takes about 3 seconds and Code: @@: times 10 nop sub rcx,10 jnc @b <2 seconds. When I measure Sleep, my CPU is @1.2GHz so the result is ~1.2 billion ticks. When I start that tight loop, my CPU clocks up to 3.2GHz, but it will not finish in 0,375 sec because loop is a macroinstruction. You can see the time nearing 2 seconds if there are many nops in between. http://randomascii.wordpress.com/2011/07/29/rdtsc-in-the-age-of-sandybridge/ You simply cannot trust the RDTSC. I cannot tell you if my RDTSC will stay the same even if the CPU throttles. |
|||
25 Jan 2013, 12:33 |
|
revolution 25 Jan 2013, 13:13
RDTSC is probably only useful for very short timing accuracy (if done properly). For longer timing there are many many things that can affect the reading. Some things quickly off the top of my head: task switch, interrupts, thermal limits, cache contents, previous instructions in the queue, trailing instructions in the queue, memory buffer contents, etc. etc. etc.
|
|||
25 Jan 2013, 13:13 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.