Re: ReadClock question - Possible overflow?



yancheng.cheok@xxxxxxxxx wrote:
; RDTSC.ASM Agner
Fog 2003

; © 2003 GNU General Public License www.gnu.org/copyleft/gpl.html

PublicAlias _ReadClock ; Underscore needed when called from
Windows

push ebx
sub eax, eax
cpuid ; serialize
rdtsc ; read time stamp counter
push eax
push edx
sub eax, eax
cpuid ; serialize
pop edx
pop eax
pop ebx
ret
ReadClock ENDP

I was wondering when having ReadClock function to perform time
measurement. Is there any posibility that the time stamp counter will
overflow (i.e., edx:eax is alreay holding the maximum value, the next
clock cycle, it will reset to 0), hence giving inaccurate time
measurement result?

Sure, if you have a *very* fast computer running for a *very* long time :)

Be careful what you use RDTSC timing for, by the way. While overflowing
might not be too big a concern, you must take frequency-lowering into
account (power saving options, found mostly in laptops but also in
late-model desktop CPUs), and multi-core machines as well - games based on
the Unreal engine crash on AMD64x2 because they use RDTSC for timing, and
when windows schedules the game thread to another core, you get negative
time deltas. b00m.


.



Relevant Pages

  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)
  • Re: Insert a byte
    ... push ebx ... mov ebx, dword ... cmp dword, 0 ... ..e0: xor eax, eax ...
    (alt.lang.asm)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: Interesting Web Site on Open Source Development
    ... mov D§esp 0DEADBEEF call Code04013A0 ... call Code0401100 push eax lea eax D§esp+014 push Data0402124 ... push eax call 'USER32.wsprintfA' add esp 0C push 030 lea ecx D§esp+014 push ecx ...
    (alt.lang.asm)
  • Re: Insert a byte
    ... mov, eax ... push STD_INPUT_HANDLE ... mov edx, ...
    (alt.lang.asm)