Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Measuring clock cycles

Author: Andrew Dados

Date: 01:09:41 08/08/00

Go up one level in this thread


On August 08, 2000 at 03:31:21, James Robertson wrote:

>On August 08, 2000 at 03:06:48, Andrew Dados wrote:
>
>>On August 08, 2000 at 02:34:54, James Robertson wrote:
>>
>>>On August 08, 2000 at 01:54:48, Andrew Dados wrote:
>>>
>>>>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
>>>
>>>Thanks, this looks cool. Unfortunately, I don't know how to interpret the db
>>>instructions... how can I use them in VC++?
>>>
>>>James
>>>
>>>
>>>>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-
>>
>>db srands for 'define byte' and is standard asm directive...
>>Look up eg crafty source for how to write procedures in assembler and readable
>>by C compilers.
>
>I've written a large amount of assembler.
>The compiler chokes on the arguments, not the db statement itself. :(
>
>James

Hmm.. instead of $0f try 0x0f etc...  :)
(I copied/pasted that code from my delphi proggy, forgot about hex convention)
-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.