-
Rdtsc
Hi I was wondering I've been looking through the web trying to find out if the C library or a way to use RDTSC and havent been able to get a good understanding or a good sample.. Im really just trying to see how to write a simple call function of RDtsc just to get an idea of the syntax.
-
Google has plenty of stuff, including examples of C code, for various timers.
High Precision Event Timer - Wikipedia, the free encyclopedia
and check out the references at the bottom of the page, as well.
Pentium Time Stamp Counter
Pentium Time Stamp Counter
On a Pentium, you are able to get the number of clock cycles since the CPU was powered up or reset. Determining the difference between two polls of the CPU for the number of clock cycles is a very effective way to time your code. The rdtsc instruction is used to move the 64-bit counter value into the resgisters EDX:EAX. Below is a piece of code that will return the 64-bit wide counter value. Note that this should work on both i386 and x86_64 architectures.
Code:
unsigned long long int rdtsc(void)
{
unsigned long long int x;
unsigned a, d;
__asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
return ((unsigned long long)a) | (((unsigned long long)d) << 32);;
}
This function will return a single "unsigned long long int" value that is the 64-bit wide counter.
-
If you're using Microsoft's compiler you can use it as an intrinsic function like this:
Code:
#include <intrin.h>
#pragma intrinsic(__rdtsc)
int main()
{
__int64 i;
i = __rdtsc();
}
-
Disgusting AT&T syntax.
Anyway, don't use that timer directly. It will cause bugs on multi-core processors.
You should use an appropriate function instead. Such a function is QueryPerformanceCounter (I believe that's right) for Windows. There are other such APIs with other operating systems.
-
Quote:
Originally Posted by
Elysia
Disgusting AT&T syntax.
I don't understand why people don't like AT&T syntax. The disgusting thing here is x86 assembly. Why can't we all just use SPARC, it has beautiful assembly.
-
Im sorry i now this is stupid and i should have mentioned this earlier but i need it for a andriod function so im calling a native call in C then im going to try and use RDTSC but i tried the BMJ one on Visual and that works thanks would it work for droid app? when im doing a jni with it
-
Does your android run on an x86 processor?
If not, using the rdtsc instruction (or it's wrapper function) just isn't going to work.
Exactly how accurate do you need this to be? What are you going to use it for?