Re: Fastcode CharPosRev B&V 0.6.0



Hi John,

I made your version to an range checking safe one, but it's a little bit
slower because the P := part
on your program becomes:
lea edx,[edx+esi-$0c]

while mine solution:
mov eax,edi
xor edx,edx
push edx
push eax
mov eax,esi
sub eax,$0c
cdq
add eax,[esp]
adc edx,[esp+$04]
add esp,$08

so that's a bummer :(

anyone have an better idea?

this is the function by the way...
function CharPosRev_DLA_PAS_9_a(SearchChar: Char; const S: string): Integer;
var
P: PByteArray;
{ Made John's PAS_03 range checking save }
begin
Result := Length(S);
if Result > 0 then
begin
P := Pointer(Cardinal(S) + (Result - 12));
repeat

if P^[11] = Byte(SearchChar) then
Exit;
if P^[10] = Byte(SearchChar) then
begin
Dec(Result);
Break;
end;
if P^[9] = Byte(SearchChar) then
begin
Dec(Result, 2);
Break;
end;
if P^[8] = Byte(SearchChar) then
begin
Dec(Result, 3);
Break;
end;
Dec(Result, 4);
if Result <= 0 then
Break;

if P^[7] = Byte(SearchChar) then
Exit;
if P^[6] = Byte(SearchChar) then
begin
Dec(Result);
Break;
end;
if P[5] = Byte(SearchChar) then
begin
Dec(Result, 2);
Break;
end;
if P[4] = Byte(SearchChar) then
begin
Dec(Result, 3);
Break;
end;
Dec(Result, 4);
if Result <= 0 then
Break;

if P[3] = Byte(SearchChar) then
Exit;
if P[2] = Byte(SearchChar) then
begin
Dec(Result);
Break;
end;
if P[1] = Byte(SearchChar) then
begin
Dec(Result, 2);
Break;
end;
if P^[0] = Byte(SearchChar) then
begin
Dec(Result, 3);
Break;
end;
Dec(Result, 4);
if Result <= 0 then
Break;
P := Pointer(Cardinal(P) - 12);
until False;
if Result < 0 then {Match Found before First Char}
Result := 0;
end;
end;

Regards,
Davy


.



Relevant Pages

  • Re: Fastcode CharPosRev B&V 0.6.0
    ... mov eax,edi ... and I learned the cdq has to do with the negative carry bit.. ... but the part where it's slower is that delphi chooses some different ...
    (borland.public.delphi.language.basm)
  • Re: Hashing
    ... mov,ecx ... xor edx,edx ...
    (alt.lang.asm)
  • Re: Confused by Intels Opcode docs
    ... The same goes for word/dword register and mem operands (mov ax,1 vs. mov ... The prefix variants are *always* slower than the non-prefix. ...
    (comp.lang.asm.x86)
  • Re: I need the fastest routine
    ... mov,eax ... cmp ecx, ... jl @loopfooter ...
    (borland.public.delphi.language.basm)