flat assembler
Message board for the users of flat assembler.

Index > Main > Cross-platform GetTickCount() ?

Author
Thread Post new topic Reply to topic
adnimo



Joined: 18 Jul 2008
Posts: 49
adnimo
What's the best way to make a cross-platform GetTickCount() equivalent?, I'd like to be able to return either 32bit as well as 64bit resolution timer. However I'm not sure whether it's feasible to make a proper replacement that works on almost any IA32 processor Confused

I've been playing with the RTDSC instruction, is that the right path?
Post 23 Aug 2008, 09:17
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:56; edited 1 time in total
Post 23 Aug 2008, 13:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17667
Location: In your JS exploiting you and your system
revolution
Unfortunately there is no 100% reliable way to get a high resolution counter. RDTSC is not available on all IA32 CPUs. If your requirement can be relaxed to just the later range of CPUs that do have RDTSC (ie. excluding 80386 etc.) then it is a start. However you need to ensure that you limit your thread to one CPU in a multicore setup else you can get different count values returned from each of the cores. Also, some cores change the rate of count when entering lower power modes and other cores keep to one rate, so reliable count rates can be troublesome.

Probably the best way to ensure reliable timing from a counter is the use the motherboard timer. It doesn't count as fast as RDTSC but it is available on all boards that support IA32 CPUs and doesn't change the rate of count during lower power modes. Also, it doesn't matter which CPU th thread runs on, the count value is always monotonic and increasing.
Post 23 Aug 2008, 14:42
View user's profile Send private message Visit poster's website Reply with quote
adnimo



Joined: 18 Jul 2008
Posts: 49
adnimo
Hi, thanks for the info.

So how does GetTickCount() work on windows?, I would like to have both lower and higher resolution timers, I don't mind limiting to certain CPUs, I'm guessing that the majority of the market now supports the instruction right?.

The game I'm working on targets CPUs of 300mhz and up (P2, etc) I'm not willing to support anything lower than that because I believe it's pointless.
Post 23 Aug 2008, 14:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17667
Location: In your JS exploiting you and your system
revolution
GetTickCount returns a millisecond counter however the accuracy is never actually 1ms. For all Windows systems I have used the accuracy is 10ms, ie. it counts in steps is 10ms each time.

The underlying timer for GetTickCount is the motherboard timer.

If you are using Windows then have a look at QueryPerformanceCounter, and the related QueryPerformanceFrequency. Perhaps they can give you what you need.
Post 23 Aug 2008, 15:12
View user's profile Send private message Visit poster's website Reply with quote
adnimo



Joined: 18 Jul 2008
Posts: 49
adnimo
hi, thanks. however I'm trying to achieve a platform independent timer, because I would like to compile my code in linux as well. I'm using the performance counter right now under windows, it works just great but I don't want to learn yet another api just to do the timing... why should I when its all available through asm?
Post 23 Aug 2008, 18:46
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
If you're making a game today, I think its pointless to support anything under a Core 2/Athlon 64 setup because ppl who play games go storm on newer architectures just to play @24FPS their new games Razz
If they are a player type, they already have a conf. that will play your game. CPUID/RDTSC were introduced somewhere in Pentium times and have been on every architecture since then. By architecture I mean Intel ones, AMD ones and even VIA chips (though I don't know how does an average person get or have one).

What I'm trying to say is that its safe to use this instruction Smile
Post 23 Aug 2008, 22:54
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Use some game engine, it saves load of problems for you. SDL comes to mind...
Post 24 Aug 2008, 07:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Patrick_



Joined: 11 Mar 2006
Posts: 53
Location: 127.0.0.1
Patrick_
The clock() libc function is a cross-platform GetTickCount() equivalent.
Post 24 Aug 2008, 22:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.