Browse Source

* fpc_shortstr_concat is now the same for all targets
* fpc_shortstr_append_shortstr added for optimized code generation

peter 22 years ago
parent
commit
60407e302b
4 changed files with 135 additions and 38 deletions
  1. 101 13
      rtl/i386/i386.inc
  2. 6 15
      rtl/i386/set.inc
  3. 6 1
      rtl/inc/compproc.inc
  4. 22 9
      rtl/inc/generic.inc

+ 101 - 13
rtl/i386/i386.inc

@@ -827,25 +827,108 @@ end;
 
 {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
 
-{$ifdef hascompilerproc}
-{ define a dummy fpc_shortstr_concat for i386. Only the next one }
-{ is really used by the compiler, but the compilerproc forward   }
-{ definition must still be fulfilled (JM)                        }
-function fpc_shortstr_concat(const s1,s2: shortstring): shortstring; compilerproc;
+function fpc_shortstr_concat(const s1,s2:shortstring):shortstring;{$ifdef hascompilerproc}compilerproc;{$endif}
 begin
-  { avoid warning }
-  fpc_shortstr_concat := '';
-  runerror(216);
+  asm
+        movl    __RESULT,%edi
+        movl    %edi,%ebx
+        movl    s1,%esi         { first string }
+        lodsb
+        andl    $0x0ff,%eax
+        stosb
+        cmpl    $7,%eax
+        jl      .LStrConcat1
+        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
+.LStrConcat1:
+        movl    %eax,%ecx
+        rep
+        movsb
+        movl    s2,%esi       { second string }
+        movzbl  (%ebx),%ecx
+        negl    %ecx
+        addl    $0x0ff,%ecx
+        lodsb
+        cmpl    %ecx,%eax
+        jbe     .LStrConcat2
+        movl    %ecx,%eax
+.LStrConcat2:
+        addb    %al,(%ebx)
+        cmpl    $7,%eax
+        jl      .LStrConcat3
+        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
+.LStrConcat3:
+        movl    %eax,%ecx
+        rep
+        movsb
+  end ['EBX','ECX','EAX','ESI','EDI'];
 end;
-{$endif hascompilerproc}
 
 
-procedure fpc_shortstr_concat_intern(const s1, s2:shortstring);
-  [public,alias:'FPC_SHORTSTR_CONCAT'];
+{$define FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
+
+{$ifdef hascompilerproc}
+procedure fpc_shortstr_append_shortstr(var s1:shortstring;const s2:shortstring);compilerproc;
+begin
+  asm
+        movl    s1,%edi
+        movl    s2,%esi
+        movl    %edi,%ebx
+        movzbl  (%edi),%ecx
+        xor     %eax,%eax
+        lea     1(%edi,%ecx),%edi
+        negl    %ecx
+        addl    $0x0ff,%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;
+{$else hascompilerproc}
+procedure fpc_shortstr_concat_int(const s1,s2:shortstring);[public,alias:'FPC_SHORTSTR_CONCAT'];
 begin
   asm
-        movl    s2,%edi
         movl    s1,%esi
+        movl    s2,%edi
         movl    %edi,%ebx
         movzbl  (%edi),%ecx
         xor     %eax,%eax
@@ -877,6 +960,7 @@ begin
         movsb
   end ['EBX','ECX','EAX','ESI','EDI'];
 end;
+{$endif hascompilerproc}
 
 
 {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
@@ -1171,7 +1255,11 @@ end;
 
 {
   $Log$
-  Revision 1.42  2003-05-16 22:40:11  florian
+  Revision 1.43  2003-05-26 19:36:46  peter
+    * fpc_shortstr_concat is now the same for all targets
+    * fpc_shortstr_append_shortstr added for optimized code generation
+
+  Revision 1.42  2003/05/16 22:40:11  florian
     * fixed generic shortstr_compare
 
   Revision 1.41  2003/03/26 00:19:10  peter

+ 6 - 15
rtl/i386/set.inc

@@ -230,29 +230,16 @@ end;
 
 {$define FPC_SYSTEM_HAS_FPC_SET_IN_BYTE}
 
-
-{$ifdef hascompilerproc}
-{ it's inlined in the code generator }
-function fpc_set_in_byte(const p: fpc_normal_set; b: byte): boolean; compilerproc;
-begin
-  { make sure we won't accidentally call it }
-  runerror(216);
-end;
-{$endif hascompilerproc}
-
-function fpc_set_in_byte_i386(p: pointer; b : byte): boolean;assembler;[public,alias:'FPC_SET_IN_BYTE'];
+function fpc_set_in_byte(const p: fpc_normal_set; b: byte): boolean; assembler; [public,alias:'FPC_SET_IN_BYTE']; {$ifdef hascompilerproc} compilerproc; {$else} saveregisters; {$endif}
 {
   tests if the element b is in the set p the carryflag is set if it present
 }
 asm
-{ it's inlined in the code generator }
-{$ifndef hascompilerproc}
        pushl %eax
        movl   p,%edi
        movzbl b,%eax
        btl %eax,(%edi)
        popl %eax
-{$endif not hascompilerproc}
 end;
 
 
@@ -595,7 +582,11 @@ end;
 
 {
   $Log$
-  Revision 1.9  2002-09-07 16:01:19  peter
+  Revision 1.10  2003-05-26 19:36:46  peter
+    * fpc_shortstr_concat is now the same for all targets
+    * fpc_shortstr_append_shortstr added for optimized code generation
+
+  Revision 1.9  2002/09/07 16:01:19  peter
     * old logs removed and tabs fixed
 
   Revision 1.8  2002/03/29 20:15:44  peter

+ 6 - 1
rtl/inc/compproc.inc

@@ -43,6 +43,7 @@ Procedure fpc_freemem(p:pointer);compilerproc;
 procedure fpc_Shortstr_SetLength(var s:shortstring;len:StrLenInt); compilerproc;
 function fpc_shortstr_to_shortstr(len:longint; const sstr: shortstring): shortstring; compilerproc;
 function fpc_shortstr_concat(const s1,s2:shortstring): shortstring; compilerproc;
+procedure fpc_shortstr_append_shortstr(var s1:shortstring;const s2:shortstring); compilerproc;
 function fpc_shortstr_compare(const left,right:shortstring) : longint; compilerproc;
 
 function fpc_pchar_to_shortstr(p:pchar):shortstring; compilerproc;
@@ -290,7 +291,11 @@ function fpc_qword_to_double(q: qword): double; compilerproc;
 
 {
   $Log$
-  Revision 1.42  2003-05-16 22:40:11  florian
+  Revision 1.43  2003-05-26 19:36:46  peter
+    * fpc_shortstr_concat is now the same for all targets
+    * fpc_shortstr_append_shortstr added for optimized code generation
+
+  Revision 1.42  2003/05/16 22:40:11  florian
     * fixed generic shortstr_compare
 
   Revision 1.41  2003/05/13 19:18:08  peter

+ 22 - 9
rtl/inc/generic.inc

@@ -556,28 +556,37 @@ end;
 
 {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
 
-{ note: this routine is *DIFFERENT* from the routine in i386.inc and as such you }
-{ cannot use it with the i386 compiler, unless you remove the                    }
-{ ti386addnode.first_string method (JM)                                          }
 function fpc_shortstr_concat(const s1,s2:shortstring): shortstring;[public,alias:'FPC_SHORTSTR_CONCAT']; {$ifdef hascompilerproc} compilerproc; {$endif}
 var
   s1l, s2l : byte;
 begin
-{ these are shortstrings, they can't be nil! (JM)
-  if (s1=nil) or (s2=nil) then
-    exit;
-}
   s1l:=length(s1);
   s2l:=length(s2);
   if s1l+s2l>255 then
     s2l:=255-s1l;
-  fpc_shortstr_concat := s1;
+  move(s1[1],fpc_shortstr_concat[1],s1l);
   move(s2[1],fpc_shortstr_concat[s1l+1],s2l);
   fpc_shortstr_concat[0]:=chr(s1l+s2l);
 end;
 
 {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
 
+{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
+
+procedure fpc_shortstr_append_shortstr(var s1:shortstring;const s2:shortstring);{$ifdef hascompilerproc} compilerproc; {$endif}
+var
+  s1l, s2l : byte;
+begin
+  s1l:=length(s1);
+  s2l:=length(s2);
+  if s1l+s2l>255 then
+    s2l:=255-s1l;
+  move(s2[1],s1[s1l+1],s2l);
+  s1[0]:=chr(s1l+s2l);
+end;
+
+{$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
+
 {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
 
 function fpc_shortstr_compare(const left,right:shortstring) : longint;[public,alias:'FPC_SHORTSTR_COMPARE']; {$ifdef hascompilerproc} compilerproc; {$endif}
@@ -965,7 +974,11 @@ end;
 
 {
   $Log$
-  Revision 1.57  2003-05-16 22:40:11  florian
+  Revision 1.58  2003-05-26 19:36:46  peter
+    * fpc_shortstr_concat is now the same for all targets
+    * fpc_shortstr_append_shortstr added for optimized code generation
+
+  Revision 1.57  2003/05/16 22:40:11  florian
     * fixed generic shortstr_compare
 
   Revision 1.56  2003/05/13 20:52:50  peter