[fpc-devel] Re: Faster Implementation for IntToStr

Max Nazhalov stein_nospam at mail.ru
Sun Sep 2 14:46:18 CEST 2012


On Sun, 02 Sep 2012, Amir wrote:

> Hi,
>    In one of my project, I have to call IntToStr more than 10M times.
> I noticed that IntToStr calls Str function. I implemented my own version
> of IntToStr which is almost twice faster than the current implementation
> of IntToStr.
> I wonder if it is possible to use my code in IntToStr function.

There are 4 generic routines in "./FPC_SRC/rtl/inc/generic.inc":

 procedure int_str(l:longint;out s:shortstring);
 procedure int_str_unsigned(l:longword;out s:shortstring);
 procedure int_str(l:int64;out s:shortstring);
 procedure int_str_unsigned(l:qword;out s:shortstring);

And also an i386-speciic assembler variants in "./FPC_SRC/rtl/i386/i386.inc", which I suspect use approach similar to yours, but I'm not sure they are "enabled"..

{$if defined(disabled) and defined(regcall)}
 procedure int_str(l:longword;out s:string);
 ...
 procedure int_str(l:longint;out s:string);
 {Optimized for speed, but balanced with size.}
 const digits:array[0..9] of cardinal=
 (0,10,100,1000,10000,
  100000,1000000,10000000,
  100000000,1000000000);
 ...
{$endif}

So You can try to propose your changes to "generic.inc"..

---
WBR,
Max.





More information about the fpc-devel mailing list