2001-10-21 Michael Hope <michaelh@juju.net.nz>
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 22 Oct 2001 01:14:16 +0000 (01:14 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 22 Oct 2001 01:14:16 +0000 (01:14 +0000)
        * src/z80/ralloc.c: Turned off faulty pack for one use.

        * src/z80/peeph-gbz80.def: Removed redundent restart options.

        * src/z80/gen.c (genMult): Added native mul for constants on the z80 and gbz80.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1429 4a8a32a2-be11-0410-ad9d-d568d2c75423

17 files changed:
ChangeLog
src/SDCCopt.c
src/SDCCpeeph.c
src/avr/main.c
src/ds390/main.c
src/izt/i186.c
src/izt/tlcs900h.c
src/mcs51/main.c
src/pic/main.c
src/port.h
src/z80/gen.c
src/z80/main.c
src/z80/peeph-gbz80.def
src/z80/peeph.def
src/z80/ralloc.c
support/tests/dhrystone/Makefile
support/tests/dhrystone/dhry.c

index df6a9108f6e39656fea1ad1b497b2882409a5417..bff727d1add6f2ac4a717fa9e994646f142c479e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2001-10-21  Michael Hope  <michaelh@juju.net.nz>
+
+       * src/z80/ralloc.c: Turned off faulty pack for one use.
+
+       * src/z80/peeph-gbz80.def: Removed redundent restart options.
+
+       * src/z80/gen.c (genMult): Added native mul for constants on the z80 and gbz80.
+
 2001-10-21  Bernhard Held  <bernhard@bernhardheld.de>
 
        * support/regression/Makefile: Improved clean
 
        * support/regression/ports/mcs51/timeout.c: little improvements
 
+2001-10-17  Michael Hope  <michaelh@juju.net.nz>
+
+       * device/lib/malloc.c (MEMHEADER): Fixed against new pedantic pointers.
+
+       * support/regression/fwk/include/testfwk.h: Fixed up to use function pts correctly.
+
+       * support/regression/generate-cases.py: Fixed up to use function pts correctly.
 
 2001-10-16  Bernhard Held  <bernhard@bernhardheld.de>
 
@@ -20,6 +35,9 @@
        * support/regression/port/mcs51/timeout.c: add timeout for uCsim
 
 2001-10-13  Michael Hope  <michaelh@juju.net.nz>
+       * src/z80/gen.c (emitCall): Fixed up missing spill of HL when used to assign the result value.
+
+       * src/z80/ralloc.c: Turned off pack for one use as it's quite broken.
 
        * src/SDCCmain.c (linkEdit): Added support for passing a legacy command line through the processor.
 
index 1fd2e6cb408cea90fc46989949c547e84dfad4c4..9d39029259c7eb62a2078041f0725e51c376e474 100644 (file)
@@ -464,10 +464,21 @@ convertToFcall (eBBlock ** ebbs, int count)
          /* if long / int mult or divide or mod */
          if (ic->op == '*' || ic->op == '/' || ic->op == '%')
            {
-             sym_link *type = operandType (IC_LEFT (ic));
-             if (IS_INTEGRAL (type) && getSize (type) > port->support.muldiv)
+             sym_link *leftType = operandType (IC_LEFT (ic));
+
+             if (IS_INTEGRAL (leftType) && getSize (leftType) > port->support.muldiv)
                 {
-                  convilong (ic, ebbs[i], type, ic->op);
+                  sym_link *rightType = operandType (IC_RIGHT (ic));
+
+                  if (port->hasNativeMulFor != NULL &&
+                      port->hasNativeMulFor (ic, leftType, rightType))
+                    {
+                      /* Leave as native */
+                    }
+                  else
+                    {
+                      convilong (ic, ebbs[i], leftType, ic->op);
+                    }
                 }
            }
           
index ada11ff9e4a431c3adda955b18b16f6d431af2cf..8797ce6c41301380fdb8ef2cafc979a7cdde3f5d 100644 (file)
@@ -748,6 +748,7 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr)
       lbp = lb;
 
       l = pl->line;
+
       while (*l)
        {
          /* if the line contains a variable */
@@ -982,8 +983,6 @@ peepHole (lineNode ** pls)
       /* for all rules */
       for (pr = rootRules; pr; pr = pr->next)
         {
-          fflush(stdout);
-          
           for (spl = *pls; spl; spl = spl->next)
             {
               /* if inline assembler then no peep hole */
@@ -991,7 +990,7 @@ peepHole (lineNode ** pls)
                 continue;
               
               mtail = NULL;
-              
+
               /* Tidy up any data stored in the hTab */
               
               /* if it matches */
index 1be9c7f5b0382c522bba9f0decd7f3e2db6d3a0d..b097d09362c23d12ee03bced59b047373fa53190 100644 (file)
@@ -209,6 +209,7 @@ PORT avr_port = {
        _avr_regparm,
         NULL,
        NULL,
+        NULL,
        FALSE,
        0,                      /* leave lt */
        1,                      /* transform gt ==> not le */
index 5693c821c4d08a672ff9b2bb4250a76c015bab96..94fd18d4aa71f0aeebe559c7c8930829ea16a186 100644 (file)
@@ -275,6 +275,7 @@ PORT ds390_port =
   _ds390_regparm,
   NULL,
   NULL,
+  NULL,
   FALSE,
   0,                           /* leave lt */
   0,                           /* leave gt */
index ba4742e46ffeb9eb945a8c32522277d00a01637a..0b3a6b17dd637ab44cc801e3e317bb399759acf7 100644 (file)
@@ -200,6 +200,7 @@ PORT i186_port = {
     _i186_regparm,
     NULL,
     NULL,
+    NULL,
     FALSE,
     0,  /* leave lt */
     0,  /* leave gt */
index b06c141cb7124ce7d9b0da7607e96b89facd7272..8cfc51616c61f7de5ff02e4dba1b92cb3cf08b87 100644 (file)
@@ -199,6 +199,7 @@ PORT tlcs900h_port =
   _tlcs900h_regparm,
   NULL,
   NULL,
+  NULL,
   FALSE,
   0,                           /* leave lt */
   0,                           /* leave gt */
index 8731cfb791a312f57f9deedf8660dcd3e2c69d2f..c20e80379dfb579915538e3bec0326f193a1e6e9 100644 (file)
@@ -207,6 +207,7 @@ PORT mcs51_port =
   _mcs51_regparm,
   NULL,
   NULL,
+  NULL,
   FALSE,
   0,                           /* leave lt */
   0,                           /* leave gt */
index b127324a07ed49aacc5862b580b7b214e27d2ddc..60443f663b68ba38df0717a8ed483629e1ed982c 100644 (file)
@@ -290,6 +290,7 @@ PORT pic_port =
   _pic14_regparm,
   NULL,
   NULL,
+  NULL,
   FALSE,
   0,                           /* leave lt */
   0,                           /* leave gt */
index d01887c80f447d33de206db38ced9505c578073c..ef0d45182754487cd1a3f3fdc0e1ff7f9139672a 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef PORT_INCLUDE
 #define PORT_INCLUDE
 
+#include "SDCCicode.h"
+
 #define TARGET_ID_MCS51    1
 #define TARGET_ID_GBZ80    2
 #define TARGET_ID_Z80      3
@@ -206,6 +208,11 @@ typedef struct
      */
     char *(*getMangledFunctionName) (char *szOrginial);
 
+    /** Returns true if the port can multiply the two types nativly
+        without using support functions.
+    */
+    bool (*hasNativeMulFor) (iCode *ic, sym_link *left, sym_link *right);
+
     /** If TRUE, then tprintf and !dw will be used for some initalisers
      */
     bool use_dw_for_init;
index 2f1f0e219363e61e5fb5029e0206f8358e7b7e56..6719b734fd9af3a0cd3e4c2bff264f137d5f7e14 100644 (file)
@@ -485,6 +485,14 @@ isPtrPair (asmop * aop)
       return FALSE;
     }
 }
+
+static void
+spillPair (PAIR_ID pairId)
+{
+  _G.pairs[pairId].last_type = AOP_INVALID;
+  _G.pairs[pairId].base = NULL;
+}
+
 /** Push a register pair onto the stack */
 void
 genPairPush (asmop * aop)
@@ -504,6 +512,7 @@ _pop (PAIR_ID pairId)
 {
   emit2 ("pop %s", _pairs[pairId].name);
   _G.stack.pushed -= 2;
+  spillPair (pairId);
 }
 
 /*-----------------------------------------------------------------*/
@@ -1037,13 +1046,6 @@ adjustPair (const char *pair, int *pold, int new)
     }
 }
 
-static void
-spillPair (PAIR_ID pairId)
-{
-  _G.pairs[pairId].last_type = AOP_INVALID;
-  _G.pairs[pairId].base = NULL;
-}
-
 static void
 spillCached (void)
 {
@@ -2403,10 +2405,11 @@ emitCall (iCode * ic, bool ispcall)
              if (i)
                emit2 ("inc sp");
            }
-         spillCached ();
        }
     }
 
+  spillCached ();
+
   if (_G.stack.pushedDE) 
     {
       bool dInUse = bitVectBitValue(rInUse, D_IDX);
@@ -3037,6 +3040,15 @@ genPlus (iCode * ic)
       goto release;
     }
 
+  if (isPair (AOP (IC_RIGHT (ic))) && AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD)
+    {
+      fetchPair (PAIR_HL, AOP (IC_LEFT (ic)));
+      emit2 ("add hl,%s", getPairName (AOP (IC_RIGHT (ic))));
+      spillCached();
+      commitPair ( AOP (IC_RESULT (ic)), PAIR_HL);
+      goto release;
+    }
+
   /* Special case:
      ld hl,sp+n trashes C so we cant afford to do it during an
      add with stack based varibles.  Worst case is:
@@ -3348,8 +3360,92 @@ release:
 static void
 genMult (iCode * ic)
 {
+  int val;
+  int count, i;
+  /* If true then the final operation should be a subtract */
+  bool active = FALSE;
+
   /* Shouldn't occur - all done through function calls */
-  wassertl (0, "Multiplication is handled through support function calls");
+  aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+  aopOp (IC_RIGHT (ic), ic, FALSE, FALSE);
+  aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
+
+  if (AOP_SIZE (IC_LEFT (ic)) > 2 ||
+      AOP_SIZE (IC_RIGHT (ic)) > 2 ||
+      AOP_SIZE (IC_RESULT (ic)) > 2)
+    {
+      wassertl (0, "Multiplication is handled through support function calls");
+    }
+
+  /* Swap left and right such that right is a literal */
+  if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT))
+    {
+      operand *t = IC_RIGHT (ic);
+      IC_RIGHT (ic) = IC_LEFT (ic);
+      IC_LEFT (ic) = t;
+    }
+
+  wassertl (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT, "Right must be a literal");
+
+  val = (int)floatFromVal ( AOP (IC_RIGHT (ic))->aopu.aop_lit);
+  //  wassertl (val > 0, "Multiply must be positive");
+  wassertl (val != 1, "Can't multiply by 1");
+
+  if (IS_Z80) {
+    _push (PAIR_DE);
+  }
+
+  if ( AOP_SIZE (IC_LEFT (ic)) == 1 && !SPEC_USIGN (getSpec (operandType ( IC_LEFT (ic)))))
+    {
+      emit2 ("ld e,%s", aopGet (AOP (IC_LEFT (ic)), LSB, FALSE));
+      emit2 ("ld a,e");
+      emit2 ("rlc a");
+      emit2 ("sbc a,a");
+      emit2 ("ld d,a");
+    }
+  else
+    {
+      fetchPair (PAIR_DE, AOP (IC_LEFT (ic)));
+    }
+
+  i = val;
+
+  /* Fully unroled version of mul.s.  Not the most efficient.
+   */
+  for (count = 0; count < 16; count++)
+    {
+      if (count != 0 && active)
+        {
+          emit2 ("add hl,hl");
+        }
+      if (i & 0x8000U)
+        {
+          if (active == FALSE)
+            {
+              emit2 ("ld l,e");
+              emit2 ("ld h,d");
+            }
+          else
+            {
+              emit2 ("add hl,de");
+            }
+          active = TRUE;
+        }
+      i <<= 1;
+    }
+
+  spillCached();
+
+  if (IS_Z80)
+    {
+      _pop (PAIR_DE);
+    }
+
+  commitPair ( AOP (IC_RESULT (ic)), PAIR_HL);
+
+  freeAsmop (IC_LEFT (ic), NULL, ic);
+  freeAsmop (IC_RIGHT (ic), NULL, ic);
+  freeAsmop (IC_RESULT (ic), NULL, ic);
 }
 
 /*-----------------------------------------------------------------*/
index 8db371fdcfbfedabf41687dfeacf563f72bfdf40..a3d70ca92469abcc0c5268e59a772da4ed4b3bba 100644 (file)
@@ -386,6 +386,40 @@ _getRegName (struct regs *reg)
   return "err";
 }
 
+static bool
+_hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
+{
+  sym_link *test = NULL;
+  value *val;
+
+  if ( ic->op != '*')
+    {
+      return FALSE;
+    }
+
+  if ( IS_LITERAL (left))
+    {
+      test = left;
+      val = OP_VALUE (IC_LEFT (ic));
+    }
+  else if ( IS_LITERAL (right))
+    {
+      test = left;
+      val = OP_VALUE (IC_RIGHT (ic));
+    }
+  else
+    {
+      return FALSE;
+    }
+
+  if ( getSize (test) <= 2)
+    {
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 #define LINKCMD \
     "{bindir}{sep}link-{port} -n -c -- {z80bases} -m -j" \
     " {z80libspec}" \
@@ -468,6 +502,7 @@ PORT z80_port =
   _reg_parm,
   _process_pragma,
   _mangleSupportFunctionName,
+  _hasNativeMulFor,
   TRUE,
   0,                           /* leave lt */
   0,                           /* leave gt */
@@ -549,6 +584,7 @@ PORT gbz80_port =
   _reg_parm,
   _process_pragma,
   _mangleSupportFunctionName,
+  _hasNativeMulFor,
   TRUE,
   0,                           /* leave lt */
   0,                           /* leave gt */
index 178a3fb4d7ea1fe35be240737a4e54789e0dcab3..846e49c9a7b6e00c2393ee318fa64f73ac479ff3 100644 (file)
@@ -1,40 +1,40 @@
-replace restart {
+replace {
+       ld      (hl),a
+        dec     hl
+} by {
+        ld      (hl-),a
+}
+replace {
        ld      (hl),a
        inc     hl
 } by {
        ld      (hl+),a
 }
-replace restart {
+replace {
        ld      a,(hl)
        inc     hl
 } by {
        ld      a,(hl+)
 }
-replace restart {
-        ld      (hl),a
-        dec     hl
-} by {
-        ld      (hl-),a
-}
-replace restart {
+replace {
        ld      a,[hl]
        inc     hl
 } by {
        ld      a,[hl+]
 }
-replace restart {
+replace {
        ld      a,[hl]
        inc     hl
 } by {
        ld      a,[hl+]
 }
-replace restart {
+replace {
        ld      [hl],a
        inc     hl
 } by {
        ld      [hl+],a
 }
-replace restart {
+replace {
        ld      [hl],a
        dec     hl
 } by {
index 6b144b3335974cc161c48e045ec79b8a987a258c..5090d4b8f45c3d20fd4b3461426eab013995c83c 100644 (file)
@@ -1,9 +1,9 @@
-replace restart {
+replace {
        ld (hl),(hl)
 } by {
        ERROR - peephole - caught (hl),(hl)
 }
-replace restart {
+replace {
        ld %1,%1
 } by {
         ; Removed redundent load
index fbd12bec46e631359a8ddcac65a735eb0a81bd0d..bc1c337e98af9f7ed13a3c2ab9ab3af07b0b069b 100644 (file)
@@ -51,7 +51,8 @@ enum
   {
     DISABLE_PACK_ACC = 0,
     DISABLE_PACK_ASSIGN = 0,
-    DISABLE_PACK_ONE_USE = 0,
+    /* Pack for one use is quite broken. */
+    DISABLE_PACK_ONE_USE = 1,
     DISABLE_PACK_HL = 0,
   };
 
@@ -2485,14 +2486,6 @@ packRegisters (eBBlock * ebp)
        packRegsForSupport (ic, ebp);
 #endif
 
-#if 0
-      /* some cases the redundant moves can
-         can be eliminated for return statements */
-      if ((ic->op == RETURN || ic->op == SEND) &&
-         !isOperandInFarSpace (IC_LEFT (ic)) &&
-         !options.model)
-       packRegsForOneuse (ic, IC_LEFT (ic), ebp);
-#endif
       /* if pointer set & left has a size more than
          one and right is not in far space */
       if (!DISABLE_PACK_ONE_USE &&
@@ -2519,6 +2512,7 @@ packRegisters (eBBlock * ebp)
 
          packRegsForOneuse (ic, IC_LEFT (ic), ebp);
        }
+
       /* pack registers for accumulator use, when the result of an
          arithmetic or bit wise operation has only one use, that use is
          immediately following the defintion and the using iCode has
@@ -2530,21 +2524,12 @@ packRegisters (eBBlock * ebp)
        {
          packRegsForHLUse (ic);
        }
-#if 0
-      if ((IS_ARITHMETIC_OP (ic)
-          || IS_BITWISE_OP (ic)
-          || ic->op == LEFT_OP || ic->op == RIGHT_OP
-         ) &&
-         IS_ITEMP (IC_RESULT (ic)) &&
-         getSize (operandType (IC_RESULT (ic))) <= 2)
-       packRegsForAccUse (ic);
-#else
+
       if (!DISABLE_PACK_ACC && IS_ITEMP (IC_RESULT (ic)) &&
          getSize (operandType (IC_RESULT (ic))) == 1)
        {
          packRegsForAccUse2 (ic);
        }
-#endif
     }
 }
 
index 4361f5e2dc72408062bbca5a3d18b819b382673d..62d194fa2e982ccf6e55d15d24705bac0bb9d051 100644 (file)
@@ -21,7 +21,7 @@ dhry.gb: dhry.c
 dhry.c: dhry.h
 
 dhry.bin: dhry.ihx
-       cat $< | ../../makebin/makebin > $@
+       cat $< | $(TOPDIR)/bin/makebin > $@
 
 native:
        gcc -g -O2 -DREG= -DNOSTRUCTASSIGN -DNOENUM -o dhry dhry.c
index 52cdb647b2335ecafc98ccf7e4cab59906b8eaa9..9154e35758208737ca794effb084e3098e56778c 100644 (file)
@@ -274,9 +274,9 @@ int main(void)
     printf ("        should be:   %d\n", (int)7);
     printf ("Enum_Loc:            %d\n", Enum_Loc);
     printf ("        should be:   %d\n", (int)1);
-    printf ("Str_1_Loc:           %s\n", (char _generic *)Str_1_Loc);
+    printf ("Str_1_Loc:           %s\n", (char *)Str_1_Loc);
     printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
-    printf ("Str_2_Loc:           %s\n", (char _generic *)Str_2_Loc);
+    printf ("Str_2_Loc:           %s\n", (char *)Str_2_Loc);
     printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
     printf ("\n");
 #endif