From 7dae81b2de3a20d5408c3c26324036de2c8a3a90 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 17 Feb 2008 12:30:30 +0000 Subject: [PATCH] * src/z80/gen.c, src/z80/peeph.def: applied patch #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 | 2 ++ src/z80/gen.c | 24 ++++++++++++++++++------ src/z80/peeph.def | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f97c0c9..de698e3e 100644 --- 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 diff --git a/src/z80/gen.c b/src/z80/gen.c index 697c3e09..db4dcf87 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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 */ diff --git a/src/z80/peeph.def b/src/z80/peeph.def index 90b1b2b1..02e485b7 100644 --- a/src/z80/peeph.def +++ b/src/z80/peeph.def @@ -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 -- 2.30.2