Re: Fastcode CharPosRev B&V 0.1.0
- From: "Dennis" <marianndkc@xxxxxxxxxxxxxxx>
- Date: Thu, 23 Nov 2006 10:14:47 +0100
Hi
Our two first functions are array based because the treat the string as an
array and indexes into it
if S[CharNo] = SearchChar then
This compiles into
cmp al,[edx+ecx-$01]
and we would like to get rid of the -$01. It comes from the fact that
element 1 of an array is located at the baseadress = edx. ecx is the CharNo.
Let us try to give the compiler an opportunity to optimize away the -$01 by
writing
if S[CharNo+1] = SearchChar then
which compiles into
cmp al,[edx+ecx]
The rest of the function will need some corrections
function CharPosRev_DKC_Pas_3_a(SearchChar : Char; const S: string) :
Integer;
var
CharNo : Integer;
begin
Result := 0;
if Length(S) > 0 then
begin
CharNo := Length(S)-1;
repeat
if S[CharNo+1] = SearchChar then
begin
Result := CharNo+1;
Break;
end;
Dec(CharNo);
until (CharNo < 0);
end;
end;
This adds extra code for subtracting and adding 1 in CharNo := Length(S)-1;
and Result := CharNo+1; The change to the first line moves our branch target
by one byte and adds a 1 cycle latency to dec ecx and this occurs for all
strings. Result := CharNo+1; adds extra code to the path of a hit
CharPosRevDKCUnit.pas.171: Result := CharNo+1;
0046C1B6 8D7101 lea esi,[ecx+$01]
versus
CharPosRevDKCUnit.pas.151: Result := CharNo;
0046C182 8BF1 mov esi,ecx
Look up the latency numbers in the reference manuals for the respective
processors.
Benchmarking on Opteron
CharPosRev_DKC_Pas_3_a 0 3014 2618 5632
CharPosRev_DKC_Pas_2_a 0 3037 2628 5665
CharPosRev_DKC_Pas_3_b 8 3058 2650 5708
CharPosRev_DKC_Pas_2_c 8 3071 2681 5752
CharPosRev_DKC_Pas_3_c 4 3482 3180 6662
CharPosRev_DKC_Pas_2_b 4 3452 3242 6694
CharPosRev_DKC_Pas_3_d C 3513 3203 6716
CharPosRev_DKC_Pas_2_d C 4655 3675 8330
We see a very small improvement
Best regards
Dennis Kjaer Christensen
----------------------------------------------------------------------------
----
Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
Den har indtil videre sparet mig for at få 5673 spam-mails
Betalende brugere får ikke denne besked i deres e-mails.
Hent en gratis SPAMfighter her.
.
- Follow-Ups:
- Re: Fastcode CharPosRev B&V 0.1.0
- From: Dennis
- Re: Fastcode CharPosRev B&V 0.1.0
- References:
- Fastcode CharPosRev B&V 0.1.0
- From: Dennis
- Re: Fastcode CharPosRev B&V 0.1.0
- From: Dennis
- Fastcode CharPosRev B&V 0.1.0
- Prev by Date: Re: Fastcode CharPosRev B&V 0.1.0
- Next by Date: Re: Fastcode CharPosRev B&V 0.1.0
- Previous by thread: Re: Fastcode CharPosRev B&V 0.1.0
- Next by thread: Re: Fastcode CharPosRev B&V 0.1.0
- Index(es):
Relevant Pages
|