* src/z80/gen.c (aopPut): fixed bug !*ixy should be !*iyx,
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 6 Aug 2006 22:36:30 +0000 (22:36 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 6 Aug 2006 22:36:30 +0000 (22:36 +0000)
  (shiftIntoPair): added case 2 for PAIR_IY,
  (setupToPreserveCarry): replaced parameters with iCode and check if
   PAIR_DE is in use to fix bug 1399290,
  (genPlus, genMinus): updated call to setupToPreserveCarry
* support/regression/tests/bug1399290.c: new

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

ChangeLog
src/z80/gen.c
support/regression/tests/bug1399290.c [new file with mode: 0644]

index 55798d6259146dbb1d6558fef1f7ad095a804d7d..20b99f43735adce85ef218d473d756c79657d910 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-08-07 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/z80/gen.c (aopPut): fixed bug !*ixy should be !*iyx,
+         (shiftIntoPair): added case 2 for PAIR_IY,
+         (setupToPreserveCarry): replaced parameters with iCode and check if
+          PAIR_DE is in use to fix bug 1399290,
+         (genPlus, genMinus): updated call to setupToPreserveCarry
+       * support/regression/tests/bug1399290.c: new
+
 2006-08-06 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * device/lib/Makefile.in (Z80SOURCES): enabled float support
index fa56bcc986354e41f762ef2ee4a3e23abd758b69..e218d9b0a280808669268326217e1266863bf0a4 100644 (file)
@@ -2067,7 +2067,7 @@ aopPut (asmop * aop, const char *s, int offset)
       if (aop->aopu.aop_pairId==PAIR_IX)
         emit2 ("ld !*ixx,%s", 0, s);
       else if (aop->aopu.aop_pairId==PAIR_IY)
-        emit2 ("ld !*ixy,%s", 0, s);
+        emit2 ("ld !*iyx,%s", 0, s);
       else
         emit2 ("ld (%s),%s", _pairs[aop->aopu.aop_pairId].name, s);
       break;
@@ -3628,30 +3628,27 @@ shiftIntoPair (int idx, asmop *aop)
   wassertl (IS_Z80, "Only implemented for the Z80");
   //  wassertl (aop->type == AOP_EXSTK, "Only implemented for EXSTK");
 
+  emitDebug ("; Shift into pair idx %u", idx);
+
   switch (idx)
     {
     case 0:
       id = PAIR_HL;
+      setupPair (PAIR_HL, aop, 0);
       break;
     case 1:
       id = PAIR_DE;
       _push (PAIR_DE);
-      break;
-    default:
-      wassertl (0, "Internal error - hit default case");
-    }
-
-  emitDebug ("; Shift into pair idx %u", idx);
-
-  if (id == PAIR_HL)
-    {
-      setupPair (PAIR_HL, aop, 0);
-    }
-  else
-    {
       setupPair (PAIR_IY, aop, 0);
       emit2 ("push iy");
       emit2 ("pop %s", _pairs[id].name);
+      break;
+    case 2:
+      id = PAIR_IY;
+      setupPair (PAIR_IY, aop, 0);
+      break;
+    default:
+      wassertl (0, "Internal error - hit default case");
     }
 
   aop->type = AOP_PAIRPTR;
@@ -3661,8 +3658,12 @@ shiftIntoPair (int idx, asmop *aop)
 }
 
 static void
-setupToPreserveCarry (asmop *result, asmop *left, asmop *right)
+setupToPreserveCarry (iCode * ic)
 {
+  asmop *left   = AOP (IC_LEFT (ic));
+  asmop *right  = AOP (IC_RIGHT (ic));
+  asmop *result = AOP (IC_RESULT (ic));
+
   wassert (left && right);
 
   if (IS_Z80)
@@ -3672,7 +3673,12 @@ setupToPreserveCarry (asmop *result, asmop *left, asmop *right)
           shiftIntoPair (0, right);
           /* check result again, in case right == result */
           if (couldDestroyCarry (result))
-            shiftIntoPair (1, result);
+            {
+              if (!isPairInUse (PAIR_DE, ic))
+                shiftIntoPair (1, result);
+              else
+                shiftIntoPair (2, result);
+            }
         }
       else if (couldDestroyCarry (right))
         {
@@ -3812,8 +3818,8 @@ genPlus (iCode * ic)
     }
 
   /* 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:
+     ld hl,sp+n trashes C so we can't afford to do it during an
+     add with stack based variables.  Worst case is:
      ld  hl,sp+left
      ld  a,(hl)
      ld  hl,sp+right
@@ -3826,7 +3832,7 @@ genPlus (iCode * ic)
      adc (hl)
      ld  hl,sp+result+1
      ld  (hl),a
-     So you cant afford to load up hl if either left, right, or result
+     So you can't afford to load up hl if either left, right, or result
      is on the stack (*sigh*)  The alt is:
      ld  hl,sp+left
      ld  de,(hl)
@@ -3882,7 +3888,7 @@ genPlus (iCode * ic)
         }
     }
 
-  setupToPreserveCarry (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)), AOP (IC_RIGHT (ic)));
+  setupToPreserveCarry (ic);
 
   while (size--)
     {
@@ -3914,7 +3920,6 @@ release:
   freeAsmop (IC_LEFT (ic), NULL, ic);
   freeAsmop (IC_RIGHT (ic), NULL, ic);
   freeAsmop (IC_RESULT (ic), NULL, ic);
-
 }
 
 /*-----------------------------------------------------------------*/
@@ -4080,7 +4085,7 @@ genMinus (iCode * ic)
         }
     }
 
-  setupToPreserveCarry (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)), AOP (IC_RIGHT (ic)));
+  setupToPreserveCarry (ic);
 
   /* if literal, add a,#-lit, else normal subb */
   while (size--)
diff --git a/support/regression/tests/bug1399290.c b/support/regression/tests/bug1399290.c
new file mode 100644 (file)
index 0000000..7024a27
--- /dev/null
@@ -0,0 +1,16 @@
+/* bug1399290.c\r
+ */\r
+#include <testfwk.h>\r
+\r
+unsigned long Left = 0x12345678;\r
+\r
+void\r
+testLongPlus(void)\r
+{\r
+       static unsigned long Result;\r
+       static unsigned long Rhs = 0x87654321;\r
+       static unsigned long *Lhs = &Left;\r
+\r
+       Result = *Lhs + Rhs;\r
+       ASSERT (Result == 0x99999999);\r
+}\r