Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Measuring clock cycles

Author: Andrew Dados

Date: 22:54:48 08/07/00

Go up one level in this thread


On August 08, 2000 at 00:25:06, James Robertson wrote:

>I am trying to measure clock cycles for certain functions in my program. Could
>sombodey please explain how to do this? Totally simple methods are preferred. :)
>
>Thanks!
>James

All modern CPUs starting with Pentium and K2 have TSC 64 bit counter which gets
incremented by 1 for each CPU clock.
Under protected mode reading from this counter is by default disabled, but for
some reason any task can enable instruction for reading TSC.

(I'll be quoting asm code I wrote before some instructions were supplied by C
inline asm, so in some cases I had to define instructions myself)

enabling TSC:

asm
db $0f, $20, $c0  {mov eax,cr4}
or eax,32         {Enable TSC}
db $0f, $22, $e0  {mov cr4,eax}
end;

reading tsc:

asm
db $0f, $31       {RDTSC : 64bit unsigned tick count goes to eax:edx}
end;

So writing mini-profiler got really easy with RDTSC.
One remark: TSC is a global counter, not task-related.

-Andrew-



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.