Implemented RFE #2485684
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 4 Jan 2009 22:25:36 +0000 (22:25 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 4 Jan 2009 22:25:36 +0000 (22:25 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5331 4a8a32a2-be11-0410-ad9d-d568d2c75423

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

index fe7453356fdfaf8afb843d02b2025d6cbb6bfdba..cfbc5e23a871c013f11bdaf737258f822ddc69f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-01-04 Philipp Klaus Krause <pkk AT spth.de>
+
+       * src/z80/gen.c:
+         Implemented RFE #2485684, and some further improvements of HL caching
+         including a bugfix.
+       * src/z80/peeph-z80.def:
+         Fixed a bug exposed by implementing RFE #2485684.
+
 2009-01-04 Philipp Klaus Krause <pkk AT spth.de>
 
        * src/z80/peeph-z80.def:
index ff07195b9d6a0a9eebe9d89c28075ad4f00b7618..296cdf2e02632f4867137455da00cd36b981302d 100644 (file)
@@ -1385,28 +1385,61 @@ fetchLitPair (PAIR_ID pairId, asmop * left, int offset)
     {
       if (pairId == PAIR_HL || pairId == PAIR_IY)
         {
-          if (_G.pairs[pairId].last_type == left->type)
+          if (_G.pairs[pairId].last_type == AOP_IMMD && left->type == AOP_IMMD)
             {
               if (_G.pairs[pairId].base && !strcmp (_G.pairs[pairId].base, base))
                 {
                   if (pairId == PAIR_HL && abs (_G.pairs[pairId].offset - offset) < 3)
                     {
                       adjustPair (pair, &_G.pairs[pairId].offset, offset);
-                      return;
+                      goto adjusted;
                     }
                   if (pairId == PAIR_IY && (offset >= INT8MIN && offset <= INT8MAX))
                     {
-                      return;
+                       goto adjusted;
                     }
                 }
             }
         }
+
+      if (pairId == PAIR_HL && left->type == AOP_LIT && _G.pairs[pairId].last_type == AOP_LIT &&
+        !IS_FLOAT (left->aopu.aop_lit->type) && offset == 0 && _G.pairs[pairId].offset == 0)
+        {
+          unsigned new_low, new_high, old_low, old_high;
+          unsigned long v_new = ulFromVal (left->aopu.aop_lit);
+          unsigned long v_old = strtoul (_G.pairs[pairId].base, NULL, 0);
+          new_low = (v_new >> 0) & 0xff;
+          new_high = (v_new >> 8) & 0xff;
+          old_low = (v_old >> 0) & 0xff;
+          old_high = (v_old >> 8) & 0xff;
+          
+          /* Change lower byte only. */
+          if(new_high == old_high)
+            {
+              emit2("ld l, %s", aopGet (left, 0, FALSE));
+              goto adjusted;
+            }
+          /* Change upper byte only. */
+          else if(new_low == old_low)
+            {
+              emit2("ld h, %s", aopGet (left, 1, FALSE));
+              goto adjusted;
+            }
+        }
+
+
       _G.pairs[pairId].last_type = left->type;
       _G.pairs[pairId].base = traceAlloc(&_G.trace.aops, Safe_strdup (base));
       _G.pairs[pairId].offset = offset;
     }
   /* Both a lit on the right and a true symbol on the left */
   emit2 ("ld %s,!hashedstr", pair, l);
+  return;
+
+adjusted:
+  _G.pairs[pairId].last_type = left->type;
+  _G.pairs[pairId].base = traceAlloc(&_G.trace.aops, Safe_strdup (base));
+  _G.pairs[pairId].offset = offset;
 }
 
 static PAIR_ID
@@ -2676,7 +2709,6 @@ genIpush (iCode * ic)
         {
           fetchHL (AOP (IC_LEFT (ic)));
           emit2 ("push hl");
-          spillPair (PAIR_HL);
           _G.stack.pushed += 2;
           goto release;
         }
@@ -2684,11 +2716,9 @@ genIpush (iCode * ic)
         {
           fetchPairLong (PAIR_HL, AOP (IC_LEFT (ic)), ic, 2);
           emit2 ("push hl");
-          spillPair (PAIR_HL);
           _G.stack.pushed += 2;
           fetchPairLong (PAIR_HL, AOP (IC_LEFT (ic)), ic, 0);
           emit2 ("push hl");
-          spillPair (PAIR_HL);
           _G.stack.pushed += 2;
           goto release;
         }
index ef6e078f74b0babb811349510f063a1072f11787..6d43c9b2439c503ca1d660a50ee2256ddffc6695 100644 (file)
@@ -1036,17 +1036,18 @@ replace restart {
 //     ; peephole 50 shortened or using a (which has just been tested to be #0x00).
 //} if operandsNotSame3(%3 '(bc)' '(de)')
 
-replace restart {
-       sub     a,%1
-       jp      NZ,%2
-       ld      a,%3
-       or      a,a
-} by {
-       sub     a,%1
-       jp      NZ,%2
-       or      a,%3
-       ; peephole 51 shortened or using a (which has just been tested to be #0x00).
-}
+// Commented out sine it triggers for %3 od the form (#...)
+//replace restart {
+//     sub     a,%1
+//     jp      NZ,%2
+//     ld      a,%3
+//     or      a,a
+//} by {
+//     sub     a,%1
+//     jp      NZ,%2
+//     or      a,%3
+//     ; peephole 51 shortened or using a (which has just been tested to be #0x00).
+//}
 //if operandsNotSame3(%3 '(bc)' '(de)')
 
 replace restart {