* some assembler functions translated to pascal

WARNING these are not yet TESTED !!!
   + FPC_CHARARRAY_TO_SHORTSTRING added
This commit is contained in:
pierre 1999-12-21 11:12:16 +00:00
parent 8b91888fc2
commit bb70445e8a

View File

@ -253,44 +253,22 @@ end;
{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY} {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY}
procedure int_strcopy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY']; procedure int_strcopy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY'];
{ var
this procedure must save all modified registers except EDI and ESI !!! slen : byte;
}
begin begin
asm if dstr=nil then
pushl %eax exit;
pushl %ecx if sstr=nil then
cld begin
movl 16(%ebp),%edi if dstr<>nil then
movl 12(%ebp),%esi pstring(dstr)^[0]:=#0;
xorl %eax,%eax exit;
movl 8(%ebp),%ecx end;
lodsb slen:=length(pstring(sstr)^);
cmpl %ecx,%eax if slen<len then
jbe .LStrCopy1 len:=slen;
movl %ecx,%eax move(sstr^,dstr^,len);
.LStrCopy1: pstring(dstr)^[0]:=chr(len);
stosb
cmpl $7,%eax
jl .LStrCopy2
movl %edi,%ecx { Align on 32bits }
negl %ecx
andl $3,%ecx
subl %ecx,%eax
rep
movsb
movl %eax,%ecx
andl $3,%eax
shrl $2,%ecx
rep
movsl
.LStrCopy2:
movl %eax,%ecx
rep
movsb
popl %ecx
popl %eax
end ['ESI','EDI'];
end; end;
{$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY} {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY}
@ -298,93 +276,48 @@ end;
{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT} {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
procedure int_strconcat(s1,s2:pointer);[public,alias:'FPC_SHORTSTR_CONCAT']; procedure int_strconcat(s1,s2:pointer);[public,alias:'FPC_SHORTSTR_CONCAT'];
var
s1l, s2l : byte;
begin begin
asm if (s1=nil) or (s2=nil) then
xorl %ecx,%ecx exit;
movl 12(%ebp),%edi s1l:=length(pstring(s1)^);
movl 8(%ebp),%esi s2l:=length(pstring(s2)^);
movl %edi,%ebx if s1l+s2l>255 then
movb (%edi),%cl s1l:=255-s2l;
lea 1(%edi,%ecx),%edi move(@(pstring(s1)^[1]),@(pstring(s2)^[s2l+1]),s1l);
negl %ecx pstring(s2)^[0]:=chr(s1l+s2l);
xor %eax,%eax
addl $0xff,%ecx
lodsb
cmpl %ecx,%eax
jbe .LStrConcat1
movl %ecx,%eax
.LStrConcat1:
addb %al,(%ebx)
cmpl $7,%eax
jl .LStrConcat2
movl %edi,%ecx { Align on 32bits }
negl %ecx
andl $3,%ecx
subl %ecx,%eax
rep
movsb
movl %eax,%ecx
andl $3,%eax
shrl $2,%ecx
rep
movsl
.LStrConcat2:
movl %eax,%ecx
rep
movsb
end ['EBX','ECX','EAX','ESI','EDI'];
end; end;
{$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT} {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE} {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
procedure int_strcmp(dstr,sstr:pointer);[public,alias:'FPC_SHORTSTR_COMPARE']; function int_strcmp(dstr,sstr:pointer) : longint;[public,alias:'FPC_SHORTSTR_COMPARE'];
var
s1,s2,max,i : byte;
d : longint;
begin begin
asm s1:=length(pstring(dstr)^);
cld s2:=length(pstring(sstr)^);
xorl %ebx,%ebx if s1<s2 then
xorl %eax,%eax max:=s1
movl 12(%ebp),%esi else
movl 8(%ebp),%edi max:=s2;
movb (%esi),%al for i:=1 to max do
movb (%edi),%bl begin
movl %eax,%edx d:=byte(pstring(dstr)^[i])-byte(pstring(sstr)^[i]);
incl %esi if d>0 then
incl %edi exit(1)
cmpl %ebx,%eax else if d<0 then
jbe .LStrCmp1 exit(-1);
movl %ebx,%eax end;
.LStrCmp1: if s1>s2 then
cmpl $7,%eax exit(1)
jl .LStrCmp2 else if s1<s2 then
movl %edi,%ecx { Align on 32bits } exit(-1)
negl %ecx else
andl $3,%ecx exit(0);
subl %ecx,%eax
orl %ecx,%ecx
rep
cmpsb
jne .LStrCmp3
movl %eax,%ecx
andl $3,%eax
shrl $2,%ecx
orl %ecx,%ecx
rep
cmpsl
je .LStrCmp2
movl $4,%eax
sub %eax,%esi
sub %eax,%edi
.LStrCmp2:
movl %eax,%ecx
orl %eax,%eax
rep
cmpsb
jne .LStrCmp3
cmp %ebx,%edx
.LStrCmp3:
end ['EDX','ECX','EBX','EAX','ESI','EDI'];
end; end;
{$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE} {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
@ -392,62 +325,46 @@ end;
{$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
function strpas(p:pchar):string;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; function strpas(p:pchar):string;[public,alias:'FPC_PCHAR_TO_SHORTSTR'];
var
l : longint;
begin begin
asm if p=nil then
cld l:=0
movl p,%edi else
movl $0xff,%ecx l:=strlen(p);
orl %edi,%edi if l>255 then
jnz .LStrPasNotNil l:=255;
decl %ecx if l>0 then
jmp .LStrPasNil move(p^,@(strpas[1]),l);
.LStrPasNotNil: strpas[0]:=chr(l);
xorl %eax,%eax
movl %edi,%esi
repne
scasb
.LStrPasNil:
movl %ecx,%eax
movl __RESULT,%edi
notb %al
decl %eax
stosb
cmpl $7,%eax
jl .LStrPas2
movl %edi,%ecx { Align on 32bits }
negl %ecx
andl $3,%ecx
subl %ecx,%eax
rep
movsb
movl %eax,%ecx
andl $3,%eax
shrl $2,%ecx
rep
movsl
.LStrPas2:
movl %eax,%ecx
rep
movsb
end ['ECX','EAX','ESI','EDI'];
end; end;
{$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
{$ifndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
function strchararray(p:pchar; l : longint):shortstring;[public,alias:'FPC_CHARARRAY_TO_SHORTSTR'];
begin
if l>=256 then
l:=255
else if l<0 then
l:=0;
move(p^,@(strchararray[1]),l);
strchararray[0]:=chr(l);
end;
{$endif ndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
{$ifndef FPC_SYSTEM_HAS_STRLEN} {$ifndef FPC_SYSTEM_HAS_STRLEN}
function strlen(p:pchar):longint;assembler; function strlen(p:pchar):longint;
asm var i : longint;
movl p,%edi begin
movl $0xffffffff,%ecx i:=0;
xorl %eax,%eax while p[i]<>#0 do inc(i);
cld exit(i);
repne end;
scasb
movl $0xfffffffe,%eax
subl %ecx,%eax
end ['EDI','ECX','EAX'];
{$endif ndef FPC_SYSTEM_HAS_STRLEN} {$endif ndef FPC_SYSTEM_HAS_STRLEN}
@ -600,7 +517,12 @@ end;
{ {
$Log$ $Log$
Revision 1.2 1999-07-05 20:04:22 peter Revision 1.3 1999-12-21 11:12:16 pierre
* some assembler functions translated to pascal
WARNING these are not yet TESTED !!!
+ FPC_CHARARRAY_TO_SHORTSTRING added
Revision 1.2 1999/07/05 20:04:22 peter
* removed temp defines * removed temp defines
Revision 1.1 1999/05/31 21:59:58 pierre Revision 1.1 1999/05/31 21:59:58 pierre