 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lars G Guest
|
Posted: Tue Nov 28, 2006 1:38 am Post subject: New function's UpperCase / LowerCase |
|
|
Hi
I think these function's without the lookup table runs reasonable fast on my
AMD64. But that about all the INTEL cpu's ?
I dont think this is the fastest function but small :-)
Regards,
Lars G
(*
Author: Lars Bloch Gravengaard
Date: 25/11 2006
Instructionset(s): PAS
Function size 79 bytes
*)
function UpperCase_LBG_Pas_1_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := PChar(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] >= 'a') and (S[CharNo+a] <= 'z') then
pResult[CharNo] := char(Ord(S[CharNo+a]) - 32);
Inc(CharNo);
until(CharNo >= Max);
end;
(*
Author: Lars Bloch Gravengaard
Date: 25/11 2006
Instructionset(s): PAS
Function size 79 bytes
*)
function LowerCase_LBG_Pas_1_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := PChar(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] >= 'A') and (S[CharNo+a] <= 'Z') then
pResult[CharNo] := char(Ord(S[CharNo+a]) + 32);
Inc(CharNo);
until(CharNo >= Max);
end; |
|
| Back to top |
|
 |
John O'Harrow Guest
|
Posted: Tue Nov 28, 2006 2:37 am Post subject: Re: New function's UpperCase / LowerCase |
|
|
Hi Lars,
Before testing, a couple of suggestions:-
The line:-
pResult := PChar(Result);
performs an unnecessary call of the @LStrToPChar function. This could be
replaced by:-
pResult := pointer(Result);
The line:-
if (S[CharNo+a] >= 'a') and (S[CharNo+a] <= 'z') then
uses 2 conditional jumps. Using
if (S[CharNo+a] in ['a'..'z']) then
instead, only uses 1 condition jump.
--
regards,
John
The Fastcode Project:
http://www.fastcodeproject.org/
"Lars G" <lbg-at-aplusmail-dot-dk> wrote in message
news:456b3e88$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi
function UpperCase_LBG_Pas_1_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := PChar(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] >= 'a') and (S[CharNo+a] <= 'z') then
pResult[CharNo] := char(Ord(S[CharNo+a]) - 32);
Inc(CharNo);
until(CharNo >= Max);
end; |
|
|
| Back to top |
|
 |
Lars G Guest
|
Posted: Tue Nov 28, 2006 3:30 am Post subject: Re: New function's UpperCase / LowerCase |
|
|
Hi John
"John O'Harrow" <john (AT) elmcrest (DOT) demon.co.uk> skrev i en meddelelse
news:456b4c5f (AT) newsgroups (DOT) borland.com...
| Quote: | Hi Lars,
Before testing, a couple of suggestions:-
The line:-
pResult := PChar(Result);
performs an unnecessary call of the @LStrToPChar function. This could be
replaced by:-
pResult := pointer(Result);
|
Thank you taking time to look at my function.
I tested you first suggestion. (UpperCase_LBG_Pas_2)
Why is that slower ? maybe mis alignment ?
UpperCase_LBG_Pas_1_a 4 117 312 429
UpperCase_LBG_Pas_1_d 0 123 348 471
UpperCase_LBG_Pas_1_c C 122 366 488
UpperCase_LBG_Pas_1_b 8 125 403 528
UpperCase_LBG_Pas_2_d 8 115 353 468
UpperCase_LBG_Pas_2_a 4 113 360 473
UpperCase_LBG_Pas_2_b 0 113 361 474
UpperCase_LBG_Pas_2_c C 119 407 526
| Quote: | The line:-
if (S[CharNo+a] >= 'a') and (S[CharNo+a] <= 'z') then
uses 2 conditional jumps. Using
if (S[CharNo+a] in ['a'..'z']) then
instead, only uses 1 condition jump.
|
UpperCase_LBG_Pas_3_d 0 119 327 446
UpperCase_LBG_Pas_3_c C 122 364 486
UpperCase_LBG_Pas_3_a 4 129 377 506
UpperCase_LBG_Pas_3_b 8 128 380 508
Again the AMD do not like the code :-(
With you suggestion we have removed
One unnecessary call and one conditional jump
And still my first function is the fastest on my AMD64 !
But the speed differens on the different alignment is smaller.
UpperCase_LBG_Pas_3 508-446 = 62
UpperCase_LBG_Pas_2 526-468 = 58
UpperCase_LBG_Pas_1 528-429 = 99
Any thought ?
Regards,
Lars G
function UpperCase_LBG_Pas_2_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := pointer(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] >= 'a') and (S[CharNo+a] <= 'z') then
pResult[CharNo] := char(Ord(S[CharNo+a]) - 32);
Inc(CharNo);
until(CharNo >= Max);
end;
function UpperCase_LBG_Pas_3_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := pointer(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] in ['a'..'z']) then
pResult[CharNo] := char(Ord(S[CharNo+a]) - 32);
Inc(CharNo);
until(CharNo >= Max);
end; |
|
| Back to top |
|
 |
Jouni Turunen Guest
|
Posted: Tue Nov 28, 2006 10:23 pm Post subject: Re: New function's UpperCase / LowerCase |
|
|
Hi Lars,
| Quote: |
function UpperCase_LBG_Pas_2_a(const S: string): string;
function UpperCase_LBG_Pas_3_a(const S: string): string;
|
Can you find out function sizes for these two if I'll
make new release on Thursday?
Regards,
Jouni
--
The Fastcode Project: http://www.fastcodeproject.org/ |
|
| Back to top |
|
 |
Lars G Guest
|
Posted: Tue Nov 28, 2006 11:51 pm Post subject: Re: New function's UpperCase / LowerCase |
|
|
"Jouni Turunen" <jouni.turunen (AT) no (DOT) spam.xenex.fi> skrev i en meddelelse
news:456c61ef (AT) newsgroups (DOT) borland.com...
| Quote: | Hi Lars,
function UpperCase_LBG_Pas_2_a(const S: string): string;
function UpperCase_LBG_Pas_3_a(const S: string): string;
Can you find out function sizes for these two if I'll
make new release on Thursday?
|
Yes
Regards,
Lars |
|
| Back to top |
|
 |
Lars G Guest
|
Posted: Wed Nov 29, 2006 12:02 am Post subject: Re: New function's UpperCase / LowerCase |
|
|
Hi Jouni
Thank you for building the release.
Regards,
Lars
(*
Author: Lars Bloch Gravengaard
Date: 27/11 2006
Instructionset(s): PAS
Function size 72 bytes
*)
function UpperCase_LBG_Pas_2_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := pointer(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] >= 'a') and (S[CharNo+a] <= 'z') then
pResult[CharNo] := char(Ord(S[CharNo+a]) - 32);
Inc(CharNo);
until(CharNo >= Max);
end;
(*
Author: Lars Bloch Gravengaard
Date: 27/11 2006
Instructionset(s): PAS
Function size 75
*)
function UpperCase_LBG_Pas_3_a(const S: string): string;
const a=1;
var
Max, CharNo : Cardinal;
pResult : PChar;
begin
Max := Length(S);
SetLength(Result, Max);
if Max <= 0 then exit;
pResult := pointer(Result);
CharNo := 0;
repeat
pResult[CharNo] := S[CharNo+a];
if (S[CharNo+a] in ['a'..'z']) then
pResult[CharNo] := char(Ord(S[CharNo+a]) - 32);
Inc(CharNo);
until(CharNo >= Max);
end;
Regards,
Lars |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|