瀏覽代碼

* use some more string routines from libc if FPC_USE_LIBC is used

Jonas Maebe 21 年之前
父節點
當前提交
f1fcf6dc6e
共有 3 個文件被更改,包括 91 次插入5 次删除
  1. 52 3
      rtl/powerpc/powerpc.inc
  2. 31 1
      rtl/powerpc/strings.inc
  3. 8 1
      rtl/powerpc/stringss.inc

+ 52 - 3
rtl/powerpc/powerpc.inc

@@ -862,6 +862,52 @@ asm
 end;
 {$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
 
+(*
+{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
+{$define FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
+
+function fpc_shortstr_concat(const s1, s2: shortstring): shortstring; compilerproc; [public, alias: 'FPC_SHORTSTR_CONCAT'];
+{ expects that (r3) contains a pointer to the result r4 to s1, r5 to s2 }
+assembler;
+asm
+      { load length s1 }
+      lbz     r6, 0(r4)
+      { load length s2 }
+      lbz     r10, 0(r5)
+      { length 0 for s1? }
+      cmplwi  cr7,r6,0
+      { length 255 for s1? }
+      subfic. r7,r6,255
+      { length 0 for s2? }
+      cmplwi  cr1,r10,0
+      { calculate min(length(s2),255-length(s1)) }
+      subc    r8,r7,r10    { r8 := r7 - r10                                }
+      cror    4*6+2,4*1+2,4*7+2
+      subfe   r7,r7,r7     { if r7 >= r10 then r7' := 0 else r7' := -1     }
+      mtctr   r6
+      and     r7,r8,r7     { if r7 >= r10 then r7' := 0 else r7' := r7-r10 }
+      add     r7,r7,r10    { if r7 >= r10 then r7' := r10 else r7' := r7   }
+
+      mr      r9,r3
+
+      { calculate length of final string }
+      add     r8,r7,r6
+      stb     r8,0(r3)
+      beq     cr7, .Lcopys1loopDone
+    .Lcopys1loop:
+      lbzu    r0,1(r4)
+      stbu    r0,1(r9)
+      bdnz    .Lcopys1loop
+    .Lcopys1loopDone:
+      mtctr   r7
+      beq     cr6, .LconcatDone
+    .Lcopys2loop:
+      lbzu    r0,1(r5)
+      stbu    r0,1(r9)
+      bdnz    .Lcopys2loop
+end;
+{$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
+*)
 
 {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
 {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
@@ -876,15 +922,15 @@ asm
       { load length s2 }
       lbz     r10, 0(r5)
       { length 0? }
-      cmplwi  r10,0
       cmplw   cr1,r6,r4
+      cmplwi  r10,0
 
       { calculate min(length(s2),high(result)-length(result)) }
       sub     r9,r4,r6
       subc    r8,r9,r10    { r8 := r9 - r10                                }
+      cror    4*7+2,4*0+2,4*1+2
       subfe   r9,r9,r9     { if r9 >= r10 then r9' := 0 else r9' := -1     }
       and     r9,r8,r9     { if r9 >= r10 then r9' := 0 else r9' := r9-r10 }
-      cror    4*7+2,4*0+2,4*1+2
       add     r9,r9,r10    { if r9 >= r10 then r9' := r10 else r9' := r9   }
 
       { calculate new length }
@@ -1091,7 +1137,10 @@ end;
 
 {
   $Log$
-  Revision 1.66  2004-04-29 20:00:47  peter
+  Revision 1.67  2004-05-01 17:02:37  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.66  2004/04/29 20:00:47  peter
     * inclocked_longint ifdef fixed
 
   Revision 1.65  2004/01/11 11:10:07  jonas

+ 31 - 1
rtl/powerpc/strings.inc

@@ -18,6 +18,7 @@
 
 { Note: the implementation of these routines is for BIG ENDIAN only!! (JM) }
 
+{$ifndef FPC_UNIT_HAS_STRCOPY}
 {$define FPC_UNIT_HAS_STRCOPY}
 function strcopy(dest,source : pchar) : pchar;assembler;
 { in: dest in r3, source in r4 }
@@ -92,8 +93,10 @@ asm
 .LStrCopyDone:
         {  r3 still contains dest here  }
 end;
+{$endif FPC_UNIT_HAS_STRCOPY}
 
 
+{$ifndef FPC_UNIT_HAS_STRECOPY}
 {$define FPC_UNIT_HAS_STRECOPY}
 function strecopy(dest,source : pchar) : pchar;assembler;
 { in: dest in r3, source in r4        }
@@ -168,8 +171,10 @@ asm
 .LStrECopyDone:
         {  r3 contains new dest here  }
 end;
+{$endif FPC_UNIT_HAS_STRECOPY}
 
 
+{$ifndef FPC_UNIT_HAS_STRLCOPY}
 {$define FPC_UNIT_HAS_STRLCOPY}
 function strlcopy(dest,source : pchar;maxlen : longint) : pchar;assembler;
 { in: dest in r3, source in r4, maxlen in r5 }
@@ -192,12 +197,17 @@ asm
         stb     r0,1(r10)
 .LStrlCopyDone:
 end;
+{$endif FPC_UNIT_HAS_STRLCOPY}
 
 
+{$ifndef FPC_UNIT_HAS_STRLEN}
 {$define FPC_UNIT_HAS_STRLEN}
 function strlen(p : pchar) : longint;assembler;
 {$i strlen.inc}
+{$endif FPC_UNIT_HAS_STRLEN}
 
+
+{$ifndef FPC_UNIT_HAS_STREND}
 {$define FPC_UNIT_HAS_STREND}
 function strend(p : pchar) : pchar;assembler;
 { in: p in r3                  }
@@ -216,8 +226,10 @@ asm
         bne     .LStrEndLoop
 .LStrEndDone:
 end;
+{$endif FPC_UNIT_HAS_STREND}
 
 
+{$ifndef FPC_UNIT_HAS_STRCOMP}
 {$define FPC_UNIT_HAS_STRCOMP}
 function strcomp(str1,str2 : pchar) : longint;assembler;
 { in: str1 in r3, str2 in r4                                                }
@@ -243,8 +255,10 @@ asm
         bne     cr1,.LStrCompLoop
 .LStrCompDone:
 end;
+{$endif FPC_UNIT_HAS_STRCOMP}
 
 
+{$ifndef FPC_UNIT_HAS_STRLCOMP}
 {$define FPC_UNIT_HAS_STRLCOMP}
 function strlcomp(str1,str2 : pchar;l : longint) : longint;assembler;
 { (same as strcomp, but maximally compare until l'th character)             }
@@ -277,8 +291,10 @@ asm
         bdnzf  cr1*4+eq,.LStrlCompLoop
 .LStrlCompDone:
 end;
+{$endif FPC_UNIT_HAS_STRLCOMP}
 
 
+{$ifndef FPC_UNIT_HAS_STRICOMP}
 {$define FPC_UNIT_HAS_STRICOMP}
 function stricomp(str1,str2 : pchar) : longint;assembler;
 { in: str1 in r3, str2 in r4                                 }
@@ -341,8 +357,10 @@ asm
         bne     cr1,.LStriCompLoop
 .LStriCompDone:
 end;
+{$endif FPC_UNIT_HAS_STRICOMP}
 
 
+{$ifndef FPC_UNIT_HAS_STRLICOMP}
 {$define FPC_UNIT_HAS_STRLICOMP}
 function strlicomp(str1,str2 : pchar;l : longint) : longint;assembler;
 { (same as stricomp, but maximally compare until l'th character) }
@@ -400,8 +418,10 @@ asm
         bdnzf    cr1*4+eq,.LStrliCompLoop
 .LStrliCompDone:
 end;
+{$endif FPC_UNIT_HAS_STRLICOMP}
 
 
+{$ifndef FPC_UNIT_HAS_STRSCAN}
 {$define FPC_UNIT_HAS_STRSCAN}
 function strscan(p : pchar;c : char) : pchar;assembler;
 asm
@@ -419,8 +439,10 @@ asm
         li      r3, 0
 .LStrScanDone:
 end;
+{$endif FPC_UNIT_HAS_STRSCAN}
 
 
+{$ifndef FPC_UNIT_HAS_STRRSCAN}
 {$define FPC_UNIT_HAS_STRRSCAN}
 function strrscan(p : pchar;c : char) : pchar;assembler;
 asm
@@ -443,8 +465,10 @@ asm
         bne     .LStrrScanLoop
 .LStrrScanDone:
 end;
+{$endif FPC_UNIT_HAS_STRRSCAN}
 
 
+{$ifndef FPC_UNIT_HAS_STRUPPER}
 {$define FPC_UNIT_HAS_STRUPPER}
 function strupper(p : pchar) : pchar;assembler;
 asm
@@ -464,8 +488,10 @@ asm
         bne     cr1,.LStrUpperLoop
 .LStrUpperNil:
 end;
+{$endif FPC_UNIT_HAS_STRUPPER}
 
 
+{$ifndef FPC_UNIT_HAS_STRLOWER}
 {$define FPC_UNIT_HAS_STRLOWER}
 function strlower(p : pchar) : pchar;assembler;
 asm
@@ -485,11 +511,15 @@ asm
         bne     cr1,.LStrLowerLoop
 .LStrLowerNil:
 end;
+{$endif FPC_UNIT_HAS_STRLOWER}
 
 
 {
   $Log$
-  Revision 1.23  2003-12-28 22:33:35  florian
+  Revision 1.24  2004-05-01 17:02:37  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.23  2003/12/28 22:33:35  florian
     * strscan fix from Jonas
 
   Revision 1.22  2003/11/29 16:27:19  jonas

+ 8 - 1
rtl/powerpc/stringss.inc

@@ -16,10 +16,13 @@
 
  **********************************************************************}
 
+{$ifndef FPC_UNIT_HAS_STRPAS}
 {$define FPC_UNIT_HAS_STRPAS}
 function strpas(p : pchar) : string; assembler;
 {$i strpas.inc}
+{$endif FPC_UNIT_HAS_STRPAS}
 
+{$ifndef FPC_UNIT_HAS_STRPCOPY}
 {$define FPC_UNIT_HAS_STRPCOPY}
 function strpcopy(d : pchar;const s : string) : pchar;assembler;
 asm
@@ -40,10 +43,14 @@ asm
 .LStrPCopyEmpty:
         stb     r0,1(r10)
 end;
+{$endif FPC_UNIT_HAS_STRPCOPY}
 
 {
   $Log$
-  Revision 1.11  2003-11-29 16:27:19  jonas
+  Revision 1.12  2004-05-01 17:02:37  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.11  2003/11/29 16:27:19  jonas
     * fixed several ppc assembler reader related problems
     * local vars in assembler procedures now start at offset 4
     * fixed second_int_to_bool (apparently an integer can be in  LOC_JUMP??)