[fpc-devel] FPC/Delphi/FastMM4/TopMemory speed test

David W Noon david.w.noon at ntlworld.com
Sat Jul 17 14:02:10 CEST 2010

On Sat, 17 Jul 2010 14:25:13 +0300, Adem wrote about Re: [fpc-devel]
FPC/Delphi/FastMM4/TopMemory speed test:

>  And, the code I used was this.
>Now, I'd like to ask why every now and then (something like 1 in 10) I 
>get a negative value for Time3 under FPC. Delphi never exhibits that 
>function GetCPUTicks: Int64;
>   RDTSC;

On a 64-bit system, the return value is in RDX, whereas the RDTSC
instruction returns its value in EDX:EAX on both 32-bit and 54-bit
systems.  This means that your returned value will sometimes contain
junk bits, and on other occasions will contain zero bits, when compiled
for a 64-bit binary.

Here is the code I use to collect timestamps:

============================= tsc.pas ==================================
unit tsc;
{ Unit to access the timestamp counter (TSC) on IA-32 (Pentium and
later) processors. }

{ Copyright (C) 2009, David W. Noon          }
{ All rights reserved,                       }

{ This code is released under the GNU Lesser General Public License
(LGPL). }


function rdtsc: qword;


{$asmmode att}
function rdtsc: qword; assembler;
	movl	%eax,__result
	movl	%edx,__result+4


The above code has been tested in both 32-bit and 64-bit binaries.

Dave  [RLU #314465]
david.w.noon at ntlworld.com (David W Noon)

More information about the fpc-devel mailing list