On 01.06.2011 22:07, Michalis Kamburelis wrote:
Any thoughts? Maybe something can be improved?

1. Why CompareMem got slower in FPC 2.4.4? Maybe something can be fixed?


Let's see...

CompareMem in 2.4.2:

=== source begin ===

function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
var
  i: cardinal;
begin
  Result:=True;
  I:=0;
  If (P1)<>(P2) then
    While Result and (i<Length) do
      begin
      Result:=PByte(P1)^=PByte(P2)^;
      Inc(I);
      Inc(pchar(P1));
      Inc(pchar(P2));
      end;
end;

=== source end ===

CompareMem in 2.4.4:

=== source begin ===

function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
begin
  Result:=CompareByte(P1^,P2^,Length)=0;
end;

=== source end ===

This at least explains why CompareMem behaves similar to CompareByte in your test :D


2. The simple comparison "(V1[0] = V2[0]) and..." is much faster than
any CompareXxx. Any chance of improving it? In this case, size is known
at compile time, so maybe CompareXxx could be "magic" and (for
reasonably small sizes) the compiler could just generate a proper code
to compare them just like "=" operator? Just an idea of course, I don't
know how easy it would be to actually implement.

The CompareMem function is in unit SysUtils and I don't think it is a good idea to "magicalize" that unit.

Maybe it's better if you or someone else would try to improve the performance of the i386 assembler code that makes up the Compare(Byte/Word/DWord) functions (it's located in rtl/i386/i386.inc btw).

Regards,
Sven
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to