* 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>
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 */
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