Sign in to follow this  
Austrian Coder

GetCycleCount

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this