Re: Fastcode CharPosRev B&V 0.6.2
- From: "Davy Landman" <davy.landman@xxxxxxxxx>
- Date: Mon, 27 Nov 2006 23:56:04 +0100
Hi,
After being beaten by John again (It's an honor ;) )
I tried one last thing..
I used labels and goto's...
function 13 and 14 I left away because they looked too much like John's..
I tried inlining the calculations, and using as much as possible foward
jumps...
I tried 16, 8 and 4 chars at once..
the 16 and 8 seem to be fast on my northwood..
function CharPosRev_DLA_PAS_14_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
Offset: Cardinal;
StrLength: Integer;
label
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 16);
while PWalk >= PStart do
begin
if PWalk[15] = SearchChar then
begin
Result := (PWalk - PStart) + 16;
Exit;
end;
if PWalk[14] = SearchChar then
begin
Result := (PWalk - PStart) + 15;
Exit;
end;
if PWalk[13] = SearchChar then
begin
Result := (PWalk - PStart) + 14;
Exit;
end;
if PWalk[12] = SearchChar then
begin
Result := (PWalk - PStart) + 13;
Exit;
end;
if PWalk[11] = SearchChar then
begin
Result := (PWalk - PStart) + 12;
Exit;
end;
if PWalk[10] = SearchChar then
begin
Result := (PWalk - PStart) + 11;
Exit;
end;
if PWalk[9] = SearchChar then
begin
Result := (PWalk - PStart) + 10;
Exit;
end;
if PWalk[8] = SearchChar then
begin
Result := (PWalk - PStart) + 9;
Exit;
end;
if PWalk[7] = SearchChar then
begin
Result := (PWalk - PStart) + 8;
Exit;
end;
if PWalk[6] = SearchChar then
begin
Result := (PWalk - PStart) + 7;
Exit;
end;
if PWalk[5] = SearchChar then
begin
Result := (PWalk - PStart) + 6;
Exit;
end;
if PWalk[4] = SearchChar then
begin
Result := (PWalk - PStart) + 5;
Exit;
end;
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
Dec(PWalk, 16);
end;
Offset := 16 - (PStart - PWalk);
PWalk := PStart;
case Offset of
0: goto c0;
1: goto c1;
2: goto c2;
3: goto c3;
4: goto c4;
5: goto c5;
6: goto c6;
7: goto c7;
8: goto c8;
9: goto c9;
10: goto c10;
11: goto c11;
12: goto c12;
13: goto c13;
14: goto c14;
15: goto c15;
16: goto c16;
end;
c16:
if PWalk[15] = SearchChar then
begin
Result := (PWalk - PStart) + 16;
Exit;
end;
c15:
if PWalk[14] = SearchChar then
begin
Result := (PWalk - PStart) + 15;
Exit;
end;
c14:
if PWalk[13] = SearchChar then
begin
Result := (PWalk - PStart) + 14;
Exit;
end;
c13:
if PWalk[12] = SearchChar then
begin
Result := (PWalk - PStart) + 13;
Exit;
end;
c12:
if PWalk[11] = SearchChar then
begin
Result := (PWalk - PStart) + 12;
Exit;
end;
c11:
if PWalk[10] = SearchChar then
begin
Result := (PWalk - PStart) + 11;
Exit;
end;
c10:
if PWalk[9] = SearchChar then
begin
Result := (PWalk - PStart) + 10;
Exit;
end;
c9:
if PWalk[8] = SearchChar then
begin
Result := (PWalk - PStart) + 9;
Exit;
end;
c8:
if PWalk[7] = SearchChar then
begin
Result := (PWalk - PStart) + 8;
Exit;
end;
c7:
if PWalk[6] = SearchChar then
begin
Result := (PWalk - PStart) + 7;
Exit;
end;
c6:
if PWalk[5] = SearchChar then
begin
Result := (PWalk - PStart) + 6;
Exit;
end;
c5:
if PWalk[4] = SearchChar then
begin
Result := (PWalk - PStart) + 5;
Exit;
end;
c4:
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
c3:
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
c2:
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
c1:
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
end;
c0:
Result := 0;
end;
function CharPosRev_DLA_PAS_15_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
Offset: Cardinal;
StrLength: Integer;
label
c0, c1, c2, c3, c4, c5, c6, c7, c8;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 8);
while PWalk >= PStart do
begin
if PWalk[7] = SearchChar then
begin
Result := (PWalk - PStart) + 8;
Exit;
end;
if PWalk[6] = SearchChar then
begin
Result := (PWalk - PStart) + 7;
Exit;
end;
if PWalk[5] = SearchChar then
begin
Result := (PWalk - PStart) + 6;
Exit;
end;
if PWalk[4] = SearchChar then
begin
Result := (PWalk - PStart) + 5;
Exit;
end;
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
Dec(PWalk, 8);
end;
Offset := 8 - (PStart - PWalk);
PWalk := PStart;
case Offset of
0: goto c0;
1: goto c1;
2: goto c2;
3: goto c3;
4: goto c4;
5: goto c5;
6: goto c6;
7: goto c7;
8: goto c8;
end;
c8:
if PWalk[7] = SearchChar then
begin
Result := (PWalk - PStart) + 8;
Exit;
end;
c7:
if PWalk[6] = SearchChar then
begin
Result := (PWalk - PStart) + 7;
Exit;
end;
c6:
if PWalk[5] = SearchChar then
begin
Result := (PWalk - PStart) + 6;
Exit;
end;
c5:
if PWalk[4] = SearchChar then
begin
Result := (PWalk - PStart) + 5;
Exit;
end;
c4:
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
c3:
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
c2:
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
c1:
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
end;
c0:
Result := 0;
end;
function CharPosRev_DLA_PAS_16_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
Offset: Cardinal;
StrLength: Integer;
label
c0, c1, c2, c3, c4;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 4);
while PWalk >= PStart do
begin
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
Dec(PWalk, 4);
end;
Offset := 4 - (PStart - PWalk);
PWalk := PStart;
case Offset of
0: goto c0;
1: goto c1;
2: goto c2;
3: goto c3;
4: goto c4;
end;
c4:
if PWalk[3] = SearchChar then
begin
Result := (PWalk - PStart) + 4;
Exit;
end;
c3:
if PWalk[2] = SearchChar then
begin
Result := (PWalk - PStart) + 3;
Exit;
end;
c2:
if PWalk[1] = SearchChar then
begin
Result := (PWalk - PStart) + 2;
Exit;
end;
c1:
if PWalk[0] = SearchChar then
begin
Result := (PWalk - PStart) + 1;
Exit;
end;
end;
c0:
Result := 0;
end;
function CharPosRev_DLA_PAS_17_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
Offset: Cardinal;
StrLength: Integer;
label
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16,
f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15,
f16;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 16);
while PWalk >= PStart do
begin
if PWalk[15] = SearchChar then
goto f16;
if PWalk[14] = SearchChar then
goto f15;
if PWalk[13] = SearchChar then
goto f14;
if PWalk[12] = SearchChar then
goto f13;
if PWalk[11] = SearchChar then
goto f12;
if PWalk[10] = SearchChar then
goto f11;
if PWalk[9] = SearchChar then
goto f10;
if PWalk[8] = SearchChar then
goto f9;
if PWalk[7] = SearchChar then
goto f8;
if PWalk[6] = SearchChar then
goto f7;
if PWalk[5] = SearchChar then
goto f6;
if PWalk[4] = SearchChar then
goto f5;
if PWalk[3] = SearchChar then
goto f4;
if PWalk[2] = SearchChar then
goto f3;
if PWalk[1] = SearchChar then
goto f2;
if PWalk[0] = SearchChar then
goto f1;
Dec(PWalk, 16);
end;
Offset := 16 - (PStart - PWalk);
PWalk := PStart;
case Offset of
0: goto c0;
1: goto c1;
2: goto c2;
3: goto c3;
4: goto c4;
5: goto c5;
6: goto c6;
7: goto c7;
8: goto c8;
9: goto c9;
10: goto c10;
11: goto c11;
12: goto c12;
13: goto c13;
14: goto c14;
15: goto c15;
16: goto c16;
end;
c16:
if PWalk[15] = SearchChar then
goto f16;
c15:
if PWalk[14] = SearchChar then
goto f15;
c14:
if PWalk[13] = SearchChar then
goto f14;
c13:
if PWalk[12] = SearchChar then
goto f13;
c12:
if PWalk[11] = SearchChar then
goto f12;
c11:
if PWalk[10] = SearchChar then
goto f11;
c10:
if PWalk[9] = SearchChar then
goto f10;
c9:
if PWalk[8] = SearchChar then
goto f9;
c8:
if PWalk[7] = SearchChar then
goto f8;
c7:
if PWalk[6] = SearchChar then
goto f7;
c6:
if PWalk[5] = SearchChar then
goto f6;
c5:
if PWalk[4] = SearchChar then
goto f5;
c4:
if PWalk[3] = SearchChar then
goto f4;
c3:
if PWalk[2] = SearchChar then
goto f3;
c2:
if PWalk[1] = SearchChar then
goto f2;
c1:
if PWalk[0] = SearchChar then
goto f1;
goto c0;
f1:
Result := (PWalk - PStart) + 1;
Exit;
f2:
Result := (PWalk - PStart) + 2;
Exit;
f3:
Result := (PWalk - PStart) + 3;
Exit;
f4:
Result := (PWalk - PStart) + 4;
Exit;
f5:
Result := (PWalk - PStart) + 5;
Exit;
f6:
Result := (PWalk - PStart) + 6;
Exit;
f7:
Result := (PWalk - PStart) + 7;
Exit;
f8:
Result := (PWalk - PStart) + 8;
Exit;
f9:
Result := (PWalk - PStart) + 9;
Exit;
f10:
Result := (PWalk - PStart) + 10;
Exit;
f11:
Result := (PWalk - PStart) + 11;
Exit;
f12:
Result := (PWalk - PStart) + 12;
Exit;
f13:
Result := (PWalk - PStart) + 13;
Exit;
f14:
Result := (PWalk - PStart) + 14;
Exit;
f15:
Result := (PWalk - PStart) + 15;
Exit;
f16:
Result := (PWalk - PStart) + 16;
Exit;
end;
c0:
Result := 0;
end;
function CharPosRev_DLA_PAS_18_a(SearchChar: Char; const S: string):
Integer;
var
PStart, PWalk: PChar;
Offset: Cardinal;
StrLength: Integer;
label
c0, c1, c2, c3, c4, c5, c6, c7, c8,
f0, f1, f2, f3, f4, f5, f6, f7, f8;
begin
StrLength := Length(S);
if StrLength > 0 then
begin
PStart := Pointer(S);
PWalk := Pointer((Cardinal(S) + Cardinal(StrLength)) - 8);
while PWalk >= PStart do
begin
if PWalk[7] = SearchChar then
goto f8;
if PWalk[6] = SearchChar then
goto f7;
if PWalk[5] = SearchChar then
goto f6;
if PWalk[4] = SearchChar then
goto f5;
if PWalk[3] = SearchChar then
goto f4;
if PWalk[2] = SearchChar then
goto f3;
if PWalk[1] = SearchChar then
goto f2;
if PWalk[0] = SearchChar then
goto f1;
Dec(PWalk, 8);
end;
Offset := 8 - (PStart - PWalk);
PWalk := PStart;
case Offset of
0: goto c0;
1: goto c1;
2: goto c2;
3: goto c3;
4: goto c4;
5: goto c5;
6: goto c6;
7: goto c7;
8: goto c8;
end;
c8:
if PWalk[7] = SearchChar then
goto f8;
c7:
if PWalk[6] = SearchChar then
goto f7;
c6:
if PWalk[5] = SearchChar then
goto f6;
c5:
if PWalk[4] = SearchChar then
goto f5;
c4:
if PWalk[3] = SearchChar then
goto f4;
c3:
if PWalk[2] = SearchChar then
goto f3;
c2:
if PWalk[1] = SearchChar then
goto f2;
c1:
if PWalk[0] = SearchChar then
goto f1;
goto c0;
f1:
Result := (PWalk - PStart) + 1;
Exit;
f2:
Result := (PWalk - PStart) + 2;
Exit;
f3:
Result := (PWalk - PStart) + 3;
Exit;
f4:
Result := (PWalk - PStart) + 4;
Exit;
f5:
Result := (PWalk - PStart) + 5;
Exit;
f6:
Result := (PWalk - PStart) + 6;
Exit;
f7:
Result := (PWalk - PStart) + 7;
Exit;
f8:
Result := (PWalk - PStart) + 8;
Exit;
end;
c0:
Result := 0;
end;
Kind regards,
Davy
.
- Follow-Ups:
- Re: Fastcode CharPosRev B&V 0.6.2
- From: Dennis
- Re: Fastcode CharPosRev B&V 0.6.2
- From: Davy Landman
- Re: Fastcode CharPosRev B&V 0.6.2
- References:
- Fastcode CharPosRev B&V 0.6.2
- From: Dennis
- Fastcode CharPosRev B&V 0.6.2
- Prev by Date: Re: Fastcode SpreadsheetCreator 0.9.8
- Next by Date: Re: Fastcode CharPosRev B&V 0.6.2
- Previous by thread: Re: Fastcode CharPosRev B&V 0.6.2
- Next by thread: Re: Fastcode CharPosRev B&V 0.6.2
- Index(es):