* src/z80/gen.c, src/z80/peeph.def: applied patch
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 17 Feb 2008 12:30:30 +0000 (12:30 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 17 Feb 2008 12:30:30 +0000 (12:30 +0000)
  #1893510: Improve logical left shift on Z80, thanks to Philipp Krause

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

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

index 6f97c0c97e88f348fe87d42d69f66d3ebf8e0e19..de698e3ebbe8d90d04e9c32209012416481c33f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,8 @@
 
        * src/z80/peeph.def: applied patch
          #1893626: Optimize tail calls on Z80, thanks to Philipp Krause
+       * src/z80/gen.c, src/z80/peeph.def: applied patch
+         #1893510: Improve logical left shift on Z80, thanks to Philipp Krause
 
 2008-02-16 Maarten Brock <sourceforge.brock AT dse.nl>
 
index 697c3e09a5672f524c1a6dd40eef05448df55c9d..db4dcf87768a6c0f9bebfb496baf9896dc9ae4a6 100644 (file)
@@ -6010,13 +6010,25 @@ shiftL1Left2Result (operand * left, int offl,
                     operand * result, int offr, int shCount)
 {
   const char *l;
-  l = aopGet (AOP (left), offl, FALSE);
-  _moveA (l);
-  /* shift left accumulator */
-  AccLsh (shCount);
-  aopPut (AOP (result), "a", offr);
-}
 
+  /* If operand and result are the same we can shift in place.
+     However shifting in acc using add is cheaper than shifting
+     in place using sla; when shifting by more than 2 shifting in
+     acc is worth the additional effort for loading from/to acc. */
+  if (sameRegs (AOP (left), AOP (result)) && shCount <= 2 && offr == offl)
+    {
+      while (shCount--)
+        emit2 ("sla %s", aopGet (AOP (result), 0, FALSE));
+    }
+  else
+    {
+      l = aopGet (AOP (left), offl, FALSE);
+      _moveA (l);
+      /* shift left accumulator */
+      AccLsh (shCount);
+      aopPut (AOP (result), "a", offr);
+    }
+}
 
 /*-----------------------------------------------------------------*/
 /* genlshTwo - left shift two bytes by known amount                */
index 90b1b2b154463a4e50e44e1ac38b62687a6e3b98..02e485b79ef257fe8c0755dcf48f0176394fe643 100644 (file)
@@ -456,6 +456,22 @@ replace restart {
        ld      %1,a
 } if notVolatile(%1)
 
+// sdcc does not use the H flag. sla resets it, while add sets it.
+// To ensure that the state of the H flag is not changed by this
+// peephole uncomment the add %3, %4 at the end (since it overwrite the H flag).
+replace restart {
+       ld      %1, a
+       sla     %1
+       ld      a, %2
+       //add   %3, %4
+} by {
+       add     a, a
+       ; peephole 42a shifts in accumulator insted of %1
+       ld      %1, a
+       ld      a, %2
+       //add   %3, %4
+}
+
 replace restart {
        ld      %1,a
        ld      a,%2