From bb70445e8a26f44a7ae6cbfb42058673e87105fd Mon Sep 17 00:00:00 2001 From: pierre Date: Tue, 21 Dec 1999 11:12:16 +0000 Subject: [PATCH] * some assembler functions translated to pascal WARNING these are not yet TESTED !!! + FPC_CHARARRAY_TO_SHORTSTRING added --- rtl/inc/generic.inc | 252 +++++++++++++++----------------------------- 1 file changed, 87 insertions(+), 165 deletions(-) diff --git a/rtl/inc/generic.inc b/rtl/inc/generic.inc index 8d28a8f62c..41ac60c8d3 100644 --- a/rtl/inc/generic.inc +++ b/rtl/inc/generic.inc @@ -253,44 +253,22 @@ end; {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY} procedure int_strcopy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY']; -{ - this procedure must save all modified registers except EDI and ESI !!! -} +var + slen : byte; begin - asm - pushl %eax - pushl %ecx - cld - movl 16(%ebp),%edi - movl 12(%ebp),%esi - xorl %eax,%eax - movl 8(%ebp),%ecx - lodsb - cmpl %ecx,%eax - jbe .LStrCopy1 - movl %ecx,%eax -.LStrCopy1: - 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']; + if dstr=nil then + exit; + if sstr=nil then + begin + if dstr<>nil then + pstring(dstr)^[0]:=#0; + exit; + end; + slen:=length(pstring(sstr)^); + if slen255 then + s1l:=255-s2l; + move(@(pstring(s1)^[1]),@(pstring(s2)^[s2l+1]),s1l); + pstring(s2)^[0]:=chr(s1l+s2l); end; {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT} {$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 - asm - cld - xorl %ebx,%ebx - xorl %eax,%eax - movl 12(%ebp),%esi - movl 8(%ebp),%edi - movb (%esi),%al - movb (%edi),%bl - movl %eax,%edx - incl %esi - incl %edi - cmpl %ebx,%eax - jbe .LStrCmp1 - movl %ebx,%eax -.LStrCmp1: - cmpl $7,%eax - jl .LStrCmp2 - movl %edi,%ecx { Align on 32bits } - negl %ecx - andl $3,%ecx - 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']; + s1:=length(pstring(dstr)^); + s2:=length(pstring(sstr)^); + if s10 then + exit(1) + else if d<0 then + exit(-1); + end; + if s1>s2 then + exit(1) + else if s1255 then + l:=255; + if l>0 then + move(p^,@(strpas[1]),l); + strpas[0]:=chr(l); end; {$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} -function strlen(p:pchar):longint;assembler; -asm - movl p,%edi - movl $0xffffffff,%ecx - xorl %eax,%eax - cld - repne - scasb - movl $0xfffffffe,%eax - subl %ecx,%eax -end ['EDI','ECX','EAX']; +function strlen(p:pchar):longint; +var i : longint; +begin + i:=0; + while p[i]<>#0 do inc(i); + exit(i); +end; {$endif ndef FPC_SYSTEM_HAS_STRLEN} @@ -600,7 +517,12 @@ end; { $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 Revision 1.1 1999/05/31 21:59:58 pierre