Re: Fastcode CharPosRev B&V 0.6.0



And here's 2 more from me:-

{$R-}
function CharPosRev_JOH_PAS_3_a(SearchChar : Char; const S: string) :
Integer;
var
P: PChar;
begin {156 Bytes}
Result := Length(S);
if Result > 0 then
begin
P := @S[Result-11];
repeat

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

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

if P[3] = SearchChar then
Exit;
if P[2] = SearchChar then
begin
Dec(Result);
Break;
end;
if P[1] = SearchChar then
begin
Dec(Result, 2);
Break;
end;
if P[0] = SearchChar then
begin
Dec(Result, 3);
Break;
end;
Dec(Result, 4);
if Result <= 0 then
Break;

Dec(P, 12);
until False;
if Result < 0 then {Match Found before First Char}
Result := 0;
end;
end;

function CharPosRev_JOH_IA32_3_a(SearchChar : Char; const S: string) :
Integer;
asm {124 Bytes}
test edx, edx {S = nil?}
mov ecx, eax {SearchChar}
jz @@NotFound {Yes, Exit with Result = 0}
mov eax, [edx-4] {Length(S)}
add edx, eax {End of String}
@@Loop:
cmp cl, [edx-1]
je @@1
cmp cl, [edx-2]
je @@2
cmp cl, [edx-3]
je @@3
cmp cl, [edx-4]
je @@4
sub eax, 4 {All Characters Checked?}
jle @@NotFound {Yes, Not Found}
cmp cl, [edx-5]
je @@1
cmp cl, [edx-6]
je @@2
cmp cl, [edx-7]
je @@3
cmp cl, [edx-8]
je @@4
sub eax, 4 {All Characters Checked?}
jle @@NotFound {Yes, Not Found}
cmp cl, [edx-9]
je @@1
cmp cl, [edx-10]
je @@2
cmp cl, [edx-11]
je @@3
cmp cl, [edx-12]
je @@4
sub eax, 4 {All Characters Checked?}
jle @@NotFound {Yes, Not Found}
cmp cl, [edx-13]
je @@1
cmp cl, [edx-14]
je @@2
cmp cl, [edx-15]
je @@3
cmp cl, [edx-16]
je @@4
sub edx, 16 {Prepare for Next Loop}
sub eax, 4 {All Characters Checked?}
jg @@Loop {No, Loop}
@@NotFound:
xor eax, eax {Result := 0}
@@1:
ret
@@4:
dec eax
@@3:
dec eax
@@2:
dec eax
js @@NotFound {Match Found before First Char}
end;

--
regards,
John

The Fastcode Project:
http://www.fastcodeproject.org/


.