From ec1a2977db2d0e4b07f61c9c6a9d0b26f63ca698 Mon Sep 17 00:00:00 2001 From: spth Date: Sun, 4 Jan 2009 22:25:36 +0000 Subject: [PATCH] Implemented RFE #2485684 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5331 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 ++++++++ src/z80/gen.c | 42 ++++++++++++++++++++++++++++++++++++------ src/z80/peeph-z80.def | 23 ++++++++++++----------- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe745335..cfbc5e23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-01-04 Philipp Klaus Krause + + * 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 * src/z80/peeph-z80.def: diff --git a/src/z80/gen.c b/src/z80/gen.c index ff07195b..296cdf2e 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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; } diff --git a/src/z80/peeph-z80.def b/src/z80/peeph-z80.def index ef6e078f..6d43c9b2 100644 --- a/src/z80/peeph-z80.def +++ b/src/z80/peeph-z80.def @@ -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 { -- 2.30.2