z80 library cleanup
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 27 Dec 2008 18:19:48 +0000 (18:19 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 27 Dec 2008 18:19:48 +0000 (18:19 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5304 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/lib/z80/mul.s
device/lib/z80/printf.c [deleted file]
device/lib/z80/string.c [deleted file]
src/z80/gen.c

index 639347d2a92689dd23c8a3e76976335b70a7596c..152b39659a8cd99a183c724390a595dd26f10d71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,13 @@
-2008-12-27 Borut Razem <borut.razem AT siol.net>
+2008-12-27 Philipp Klaus Krause <pkk AT spth.de>
+
+       * device/lib/z80/string.c,
+         device/lib/z80/printf.c,
+         device/lib/z80/mul.s:
+         z80 library cleanup
+       * src/z80/gen.c:
+         Fixed code generation bug exposed by builtin memcpy().
+
+2008-12-27 Philipp Klaus Krause <pkk AT spth.de>
 
        * device/lib/_memcpy.c:
          fixed conflict with builtin memcpy()
index 424554a732d994920348a779be65c34f3a2c466f..6dd917a1ec2c5961c24c9d838c5d27695915fa51 100644 (file)
@@ -3,6 +3,8 @@
 ; This multiplication routine is similar to the one
 ; from Rodnay Zaks, "Programming the Z80".
 
+; Now replaced by a builtin for code generation, but
+; still called from some asm files in this directory.
 __muluchar_rrx_s::
         ld      hl, #2+1
         add     hl, sp
diff --git a/device/lib/z80/printf.c b/device/lib/z80/printf.c
deleted file mode 100644 (file)
index 65c25b9..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/** Simple printf implementation
-    This stub has been replaced by the std printf_large / sprintf / vprintf
-*/
-
-#include <stdarg.h>
-#include <stdio.h>
-
-#define STATIC
-
-static void _printn(unsigned u, unsigned base, char issigned, volatile void (*emitter)(char, void *), void *pData)
-{
-    const char *_hex = "0123456789ABCDEF";
-    if (issigned && ((int)u < 0)) {
-       (*emitter)('-', pData);
-       u = (unsigned)-((int)u);
-    }
-    if (u >= base)
-       _printn(u/base, base, 0, emitter, pData);
-    (*emitter)(_hex[u%base], pData);
-}
-
-STATIC void _printf(const char *format, volatile void (*emitter)(char, void *), void *pData, va_list va)
-{
-    while (*format) {
-       if (*format == '%') {
-           switch (*++format) {
-           case 'c': {
-               char c = (char)va_arg(va, int);
-               (*emitter)(c, pData);
-               break;
-           }
-           case 'u':
-               {
-                   unsigned u = va_arg(va, unsigned);
-                   _printn(u, 10, 0, emitter, pData);
-                   break;
-               }
-           case 'd':
-               {
-                   unsigned u = va_arg(va, unsigned);
-                   _printn(u, 10, 1, emitter, pData);
-                   break;
-               }
-           case 'x':
-               {
-                   unsigned u = va_arg(va, unsigned);
-                   _printn(u, 16, 0, emitter, pData);
-                   break;
-               }
-           case 's':
-               {
-                   char *s = va_arg(va, char *);
-                   while (*s) {
-                       (*emitter)(*s, pData);
-                       s++;
-                   }
-               }
-           }
-       }
-       else {
-           (*emitter)(*format, pData);
-       }
-       format++;
-    }
-}
-
-void putchar(char c);
-
-STATIC void _char_emitter(char c, void *pData)
-{
-    /* PENDING: Make the compiler happy. */
-    pData = 0;
-
-    putchar(c);
-}
-
-int printf(const char *format, ...)
-{
-    va_list va;
-    va_start(va, format);
-
-    _printf(format, _char_emitter, NULL, va);
-
-    /* PENDING: What to return? */
-    return 0;
-}
-
-STATIC void _buf_emitter(char c, void *pData)
-{
-  *((*((char **)pData)))++ = c;
-}
-
-int sprintf(char *pInto, const char *format, ...)
-{
-    va_list va;
-    va_start(va, format);
-
-    _printf(format, _buf_emitter, &pInto, va);
-    *pInto++ = '\0';
-
-    /* PENDING: What to return? */
-    return 0;
-}
diff --git a/device/lib/z80/string.c b/device/lib/z80/string.c
deleted file mode 100644 (file)
index 53ee9b2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Dumb strings stub.
-   Wanted a quick hack for now - will use the libc version later.
-*/
-char *strcpy(char *dest, const char *source)
-{
-    char *d = dest;
-    const char *s = source;
-    while (*d++ = *s++);
-    return dest;
-}
-
-void *memcpy(void *dest, const void *source, int count)
-{
-    char *d = dest;
-    const char *s = source;
-    while (count--)
-       *d++ = *s++;
-
-    return dest;
-}
-
-int strcmp(const char *s1, const char *s2)
-{
-    char ret = 0;
-
-    while (!(ret = *s1 - *s2) && *s2)
-       ++s1, ++s2;
-
-    if (ret < 0)
-       return -1;
-    else if (ret > 0)
-       return 1;
-    return 0;
-}
index eac67d7b0b18e60694bbfce18dea1b95a692116e..817acecc230fa68f6aa29b5f22d73c2c628e9863 100644 (file)
@@ -7999,67 +7999,12 @@ _swap (PAIR_ID one, PAIR_ID two)
     }
 }
 
-/* The problem is that we may have all three pairs used and they may
-   be needed in a different order.
-
-   Note: Have ex de,hl
-
-   Combinations:
-     hl = hl            => unity, fine
-     bc = bc
-     de = de
-
-     hl = hl            hl = hl, swap de <=> bc
-     bc = de
-     de = bc
-
-     hl = bc            Worst case
-     bc = de
-     de = hl
-
-     hl = bc            de = de, swap bc <=> hl
-     bc = hl
-     de = de
-
-     hl = de            Worst case
-     bc = hl
-     de = bc
-
-     hl = de            bc = bc, swap hl <=> de
-     bc = bc
-     de = hl
-
-   Break it down into:
-    * Any pair = pair are done last
-    * Any pair = iTemp are done last
-    * Any swaps can be done any time
-
-   A worst case:
-    push p1
-    p1 = p2
-    p2 = p3
-    pop  p3
-
-   So how do we detect the cases?
-   How about a 3x3 matrix?
-        source
-   dest x x x x
-        x x x x
-        x x x x (Fourth for iTemp/other)
-
-   First determin which mode to use by counting the number of unity and
-   iTemp assigns.
-     Three - any order
-     Two - Assign the pair first, then the rest
-     One - Swap the two, then the rest
-     Zero - Worst case.
-*/
 static void
 setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
 {
   PAIR_ID ids[NUM_PAIRS][NUM_PAIRS];
   PAIR_ID dest[3] = {
-    PAIR_BC, PAIR_HL, PAIR_DE
+    PAIR_DE, PAIR_HL, PAIR_BC
   };
   int i, j, nunity = 0;
   memset (ids, PAIR_INVALID, sizeof (ids));
@@ -8067,10 +8012,6 @@ setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
   /* Sanity checks */
   wassert (nparams == 3);
 
-  /* First save everything that needs to be saved. */
-  _saveRegsForCall (ic, 0);
-
-  /* Loading HL first means that DE is always fine. */
   for (i = 0; i < nparams; i++)
     {
       aopOp (pparams[i], ic, FALSE, FALSE);
@@ -8092,7 +8033,7 @@ setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
     }
   else if (nunity == 2)
     {
-      /* One is assigned.  Pull it out and assign. */
+      /* Two are OK.  Assign the other one. */
       for (i = 0; i < 3; i++)
         {
           for (j = 0; j < NUM_PAIRS; j++)
@@ -8115,7 +8056,7 @@ setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
     }
   else if (nunity == 1)
     {
-      /* Find the pairs to swap. */
+      /* One is OK. Find the other two. */
       for (i = 0; i < 3; i++)
         {
           for (j = 0; j < NUM_PAIRS; j++)
@@ -8124,12 +8065,22 @@ setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
                 {
                   if (j == PAIR_INVALID || j == dest[i])
                     {
-                      /* Keep looking. */
+                      /* This one is OK. */
                     }
                   else
                     {
-                      _swap (j, dest[i]);
-                      goto done;
+                      /* Found one. */
+                      if(ids[j][dest[i]] == TRUE)
+                        {
+                          /* Just swap. */
+                           _swap (j, dest[i]);
+                           goto done;
+                        }
+                      else
+                        {
+                          fetchPair (dest[i], AOP (pparams[i]));
+                          continue;
+                        }         
                     }
                 }
             }
@@ -8163,7 +8114,7 @@ setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
     }
 }
 
-static void
+/*static void
 genBuiltInStrcpy (iCode *ic, int nParams, operand **pparams)
 {
   operand *from, *to;
@@ -8176,6 +8127,8 @@ genBuiltInStrcpy (iCode *ic, int nParams, operand **pparams)
 
   deInUse = bitVectBitValue (ic->rMask, D_IDX) || bitVectBitValue(ic->rMask, E_IDX);
 
+  _saveRegsForCall (ic, 0);
+
   setupForBuiltin3 (ic, nParams, pparams);
 
   label = newiTempLabel(NULL);
@@ -8188,20 +8141,19 @@ genBuiltInStrcpy (iCode *ic, int nParams, operand **pparams)
 
   freeAsmop (from, NULL, ic->next);
   freeAsmop (to, NULL, ic);
-}
+}*/
 
 static void
 genBuiltInMemcpy (iCode *ic, int nParams, operand **pparams)
 {
   operand *from, *to, *count;
-  bool deInUse;
 
   wassertl (nParams == 3, "Built-in memcpy must have three parameters");
   to = pparams[2];
   from = pparams[1];
   count = pparams[0];
 
-  deInUse = bitVectBitValue (ic->rMask, D_IDX) || bitVectBitValue(ic->rMask, E_IDX);
+  _saveRegsForCall (ic, 0);
 
   setupForBuiltin3 (ic, nParams, pparams);
 
@@ -8243,11 +8195,11 @@ static void genBuiltIn (iCode *ic)
     /* which function is it */
     bif = OP_SYMBOL(IC_LEFT(bi_iCode));
 
-    if (strcmp(bif->name,"__builtin_strcpy")==0)
+    /*if (strcmp(bif->name,"__builtin_strcpy")==0)
       {
         genBuiltInStrcpy(bi_iCode, nbi_parms, bi_parms);
       }
-    else if (strcmp(bif->name,"__builtin_memcpy")==0)
+    else*/ if (strcmp(bif->name,"__builtin_memcpy")==0)
       {
         genBuiltInMemcpy(bi_iCode, nbi_parms, bi_parms);
       }