Implemented RFE #1899189
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 25 Dec 2008 23:26:11 +0000 (23:26 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 25 Dec 2008 23:26:11 +0000 (23:26 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5299 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/z80/gen.c
src/z80/main.c
src/z80/peep.c
src/z80/peeph-z80.def

index 5cd3afa52699bca762ae08abef775ffd1b137bea..ece91a9b71bf806776d4a94134343cafd831b3fc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-12-26 Philipp Klaus Krause <pkk AT spth.de>
+
+       * src/z80/peeph-z80.def: fixed a bug in peephole 0zf
+       * src/z80/peep.c: improved checks for unused data
+       * src/z80/gen.c,
+         src/z80/main.c: Implemented RFE #1899189
+
 2008-12-25 Borut Razem <borut.razem AT siol.net>
 
        * support/regression/Makefile.in:
index 226434d2490e25db7265cadf840668edbe339691..d055c7a1cb419b62e341609c59b3ce77e52c7797 100644 (file)
@@ -4215,6 +4215,72 @@ release:
   freeAsmop (IC_RESULT (ic), NULL, ic);
 }
 
+/*-----------------------------------------------------------------*/
+/* genMultChar - generates code for unsigned 8x8 multiplication    */
+/*-----------------------------------------------------------------*/
+static void
+genMultOneChar (iCode * ic)
+{
+  symbol *tlbl1, *tlbl2;
+  bool savedB = FALSE;
+
+  if(IS_GB)
+    {
+      wassertl (0, "Multiplication is handled through support function calls on gbz80");
+      return;
+    }
+
+  /* Save b into a if b is in use. */
+  if (bitVectBitValue (ic->rMask, B_IDX) &&
+    !(getPairId (AOP (IC_RESULT (ic))) == PAIR_BC))
+    {
+      emit2 ("ld a, b");
+      savedB = TRUE;
+    }
+  if (isPairInUse (PAIR_DE, ic) &&
+    !(getPairId (AOP (IC_RESULT (ic))) == PAIR_DE))
+  {
+    _push (PAIR_DE);
+    _G.stack.pushedDE = TRUE;
+  }
+
+  tlbl1 = newiTempLabel (NULL);
+  tlbl2 = newiTempLabel (NULL);
+
+  emit2 ("ld e,%s", aopGet (AOP (IC_RIGHT (ic)), LSB, FALSE));
+  emit2 ("ld h,%s", aopGet (AOP (IC_LEFT (ic)), LSB, FALSE));
+  emit2 ("ld l,#0x00");
+  emit2 ("ld d,l");
+  emit2 ("ld b,#0x08");
+  emitLabel (tlbl1->key + 100);
+  emit2 ("add hl,hl");
+  emit2 ("jp NC,!tlabel", tlbl2->key + 100);
+  emit2 ("add hl,de");
+  emitLabel (tlbl2->key + 100);
+  emit2 ("djnz !tlabel", tlbl1->key + 100);
+
+  spillPair(PAIR_HL);
+
+  if (IS_Z80 && _G.stack.pushedDE)
+    {
+      _pop (PAIR_DE);
+      _G.stack.pushedDE = FALSE;
+    }
+  if (savedB)
+    {
+      emit2 ("ld b, a");
+    }
+
+  if (AOP_SIZE (IC_RESULT (ic)) == 1)
+    aopPut (AOP (IC_RESULT (ic)), "l", 0);
+  else
+    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);
+}
+
 /*-----------------------------------------------------------------*/
 /* genMult - generates code for multiplication                     */
 /*-----------------------------------------------------------------*/
@@ -4249,6 +4315,12 @@ genMult (iCode * ic)
       IC_LEFT (ic) = t;
     }
 
+  if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+    {
+      genMultOneChar (ic);
+      return;
+    }
+
   wassertl (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT, "Right must be a literal");
 
   val = (int) ulFromVal ( AOP (IC_RIGHT (ic))->aopu.aop_lit);
index 86501c99324a05cc6e8bb8c6949f8bbdde0dbe54..2f94e3615d7b93733eb1c1e6b46c18d94f948f1a 100644 (file)
@@ -652,6 +652,13 @@ _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
       test = right;
       val = OP_VALUE (IC_RIGHT (ic));
     }
+  /* 8x8 unsigned multiplication code is shorter than
+     call overhead for the multiplication routine. */
+  else if ( IS_CHAR (right) && IS_UNSIGNED (right) &&
+    IS_CHAR (left) && IS_UNSIGNED(left) && !IS_GB)
+    {
+      return TRUE;
+    }
   else
     {
       return FALSE;
index 7e27c07e52de6355648fc61d46d5b1f8efad36dd..ff72544bd6bf1d337f7ac256e693173a790ac2d3 100644 (file)
@@ -229,8 +229,11 @@ z80MightRead(const lineNode *pl, const char *what)
     strncmp(pl->line, "sub\t", 4) == 0 ||
     strncmp(pl->line, "xor\t", 4) == 0)
     {
-      if( strstr(pl->line + 3, what) == 0 && strcmp("a", what))
-        return FALSE;
+      if( strstr(pl->line + 3, what) != 0)
+        return TRUE;
+      if( strstr(pl->line + 3, "hl") == 0 && strcmp("a", what) == 0)
+        return TRUE;
+      return FALSE;
     }
 
   if(strncmp(pl->line, "pop\t", 4) == 0)
@@ -255,6 +258,9 @@ z80MightRead(const lineNode *pl, const char *what)
     (bool)(strncmp(pl->line, "jr\t", 3)) == 0)
     return FALSE;
 
+  if(strncmp(pl->line, "djnz\t", 5) == 0)
+    return(strchr(what, 'b') != 0);
+
   if(strncmp(pl->line, "rla", 3) == 0 ||
     strncmp(pl->line, "rlca", 4) == 0)
     return(strcmp(what, "a") == 0);
@@ -275,7 +281,8 @@ static bool
 z80CondJump(const lineNode *pl)
 {
   if((strncmp(pl->line, "jp\t", 3) == 0 ||
-    strncmp(pl->line, "jr\t", 3) == 0) && strchr(pl->line, ',') != 0)
+    strncmp(pl->line, "jr\t", 3) == 0) && strchr(pl->line, ',') != 0 ||
+    strncmp(pl->line, "djnz\t", 5) == 0)
     return TRUE;
   return FALSE;
 }
index a92ead4ebadba79ac9bc7c322a117e68bd161f49..706c6eadc488001c56801d01b0919a5d94a69ffe 100644 (file)
@@ -347,7 +347,7 @@ replace restart {
        ; peephole 0zf used hl instead of iy.
        ld      hl,#%1 + %2
        ld      (hl), %4
-} if notUsed('iy'), notUsed('hl')
+} if notUsed('iy'), notUsed('hl'), operandsNotRelated(%4 'h'), operandsNotRelated(%4 'l')
 
 replace restart {
        ld      e,l