Skip to main content
GameDev.net gamedev.net
🔒 Locked

CPUID timing

Started by drslush Jul 21, 2003 at 10:58 AM 6 replies 1.4k views
Original Post
drslush
drslush
I was just timing CPUID (because i need a serializing instruction for a timing class) and it came out to 548 cycles! Can this possibly be right? The following was my code to time CPUID:
__asm {
	CPUID 
	CPUID
	CPUID  // Call CPUID three times, since the first couple of times can take longer

	RDTSC
	PUSH EAX
	CPUID
	RDTSC
	POP EBX
	SUB EAX, EBX
}
The number of cycles should be in EAX now.
darookie
darookie
No matter if it really takes so many cycles or not -
it simply doesn't matter as you won't call CPUID
inside your main loop.

[edited by - darookie on July 21, 2003 12:04:48 PM]
drslush
drslush
I was just wondering if it was accurate. And yes, you might want to call CPUID inside your main loop, if you need a serializing instruction. For timing routines, this is quite important.
Sneftel
Sneftel
quote:
Original post by drslush
I was just wondering if it was accurate. And yes, you might want to call CPUID inside your main loop, if you need a serializing instruction. For timing routines, this is quite important.

No, you''d never do this (if you were designing it well). You''d call CPUID once, near the beginning of your program, and store whatever information you needed from it in your own variables. Then, functions which depend on CPU type would use those variables. (You could also use runtime code modification... but that''s a bit more tricky.)


How appropriate. You fight like a cow.
drslush
drslush
Sneftl, you missed my point. I''m using it as a serializing function. Modern Pentium archetecture can execute multiple instructions at the same time, as long as they arent working with the same data. So in other words if you had an fdiv in between two timing calls, you would have to use a serializing instruction (like CPUID) in order for there to be a garuntee that the instructions would be executed in order. Otherwise you cannot accurately time certain operations.
Jan Wassenberg
Jan Wassenberg
Yeah, that''s possible - I believe it is that slow on Intel CPUs. My Athlon dox call it 42 clocks.
That''s probably the best serializing instruction, too - forget iret and rsm; the rest are priviledged.
Do you really need to serialize the counter? I suppose that''d only be necessary when timing long, single instructions (e.g. div), not for a general time reference.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
drslush
drslush
I need it to be extremely accurate, but you are right that it probably isn''t really necessary. But I don''t see any reason why not to.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.