[fpc-devel] Patch to speed up Uppercase/Lowercase functions

Daniël Mantione daniel at deadlock.et.tudelft.nl
Sat Jun 11 09:01:51 CEST 2005



Op Sat, 11 Jun 2005, schreef Christian Iversen:

> On Friday 10 June 2005 17:16, Joost van der Sluis wrote:
> > Hi all,
> >
> > I don't know if rtl-optimilisation patches have a large priority, but
> > nevertheless this patch improves the speed of the sysutils.uppercase and
> > lowercase functions.
>
> A more efficient optimization would use a forward for-loop. Modern processors
> are better suited for "normal" loops*, and the most compilers optimize them
> better.
>
> * For instance, the P4 has "data stream detection", which means that it can
> pre-cache data used in a first-to-last-byte manner, but not
> last-to-first-byte.

The compiler can take advantage of automatic zero comparison, i.e. if
counting to zero one can simply say:

dec loopcounter
jnz @loop

If one counts upwards, the compiler needs to do an extra compare:

inc loopcounter
cmp loopcounter,endvalue
jne @loop

I guess the automatic prefetch of the CPU gets only activated for very
large strings, while with a very small loop body the extra cmp might be
noticeable, especially if the loop counter is not a register variable in
which case it causes an extra memory look up.

Daniël





More information about the fpc-devel mailing list