Jump to content
  • Advertisement
Sign in to follow this  
Austrian Coder

GetCycleCount

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. Can somebody help me to port this function to gcc?
		static inline unsigned __int64 GetCycleCount()
		{
			unsigned int timehi, timelo;
			
			// Use the assembly instruction rdtsc, which gets the current
			// cycle count (since the process started) and puts it in edx:eax.
			__asm
			{
				rdtsc
				mov timehi, edx;
				mov timelo, eax;
			}
			
			return ((unsigned __int64)timehi << 32) + (unsigned __int64)timelo;
		}

Thanks, AC

Share this post


Link to post
Share on other sites
Advertisement
I think this is what you want.

static inline unsigned long long int GetCycleCount()
{
unsigned long long int res = 0;
// Use the assembly instruction rdtsc, which gets the current
// cycle count (since the process started) and puts it in edx:eax.
asm volatile ("rdtsc" : "=A" (res));

return res;
}



I should point out that prior to doing this I had no idea how to do inline assembly in GCC. [smile]

PS: I tested this on g++ 3.3.1 under cygwin.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!