From a2e05e2ded0a1352041622ce3677115ee038c066 Mon Sep 17 00:00:00 2001 From: tecodev Date: Mon, 20 Nov 2006 23:21:40 +0000 Subject: [PATCH] * src/pic/device.{c,h}: added pic14_getPIC() * src/pic/gen.c (continueIfTrue,jumpIfTrue): added PIC code, (genAnd): added PIC code for one case, fixes #1597044 * src/pic/pcode.c (BankSelect): Ohoh, added generic optimization for SFRs that are present in all banks (e.g., STATUS) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4474 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 ++++++++ src/pic/device.c | 4 ++++ src/pic/device.h | 1 + src/pic/gen.c | 29 +++++++++++++++++++++++++---- src/pic/pcode.c | 4 ++++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c83c79fe..298764e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-11-21 Raphael Neider + + * src/pic/device.{c,h}: added pic14_getPIC() + * src/pic/gen.c (continueIfTrue,jumpIfTrue): added PIC code, + (genAnd): added PIC code for one case, fixes #1597044 + * src/pic/pcode.c (BankSelect): Ohoh, added generic optimization for + SFRs that are present in all banks (e.g., STATUS) + 2006-11-20 Raphael Neider * src/pic/pcode.c: changed inverted ops for DECFSZ/DECFSZW and diff --git a/src/pic/device.c b/src/pic/device.c index 5546e1f1..d6b49392 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -1062,3 +1062,7 @@ int pic14_getSharebankAddress(void) return sharebankAddress; } +PIC_device * pic14_getPIC(void) +{ + return pic; +} diff --git a/src/pic/device.h b/src/pic/device.h index bea75a49..ad8a890d 100644 --- a/src/pic/device.h +++ b/src/pic/device.h @@ -114,5 +114,6 @@ unsigned pic14_getMaxRam(void); int pic14_getHasSecondConfigReg(void); int pic14_getSharebankSize(void); int pic14_getSharebankAddress(void); +PIC_device * pic14_getPIC(void); #endif /* __DEVICE_H__ */ diff --git a/src/pic/gen.c b/src/pic/gen.c index f76cb101..fbfd19c9 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -5487,7 +5487,11 @@ static void continueIfTrue (iCode *ic) FENTRY; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); if(IC_TRUE(ic)) - pic14_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100); + { + // Why +100?!? + emitpcode(POC_GOTO, popGetLabel(IC_TRUE(ic)->key+100)); + pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100); + } ic->generated = 1; } @@ -5499,7 +5503,11 @@ static void jumpIfTrue (iCode *ic) FENTRY; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); if(!IC_TRUE(ic)) + { + // Why +100?!? + emitpcode(POC_GOTO, popGetLabel(IC_TRUE(ic)->key+100)); pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100); + } ic->generated = 1; } @@ -5640,7 +5648,7 @@ static void genAnd (iCode *ic, iCode *ifx) offset++; } emitpcode(((rIfx.condition) ? POC_BTFSC : POC_BTFSS), - newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),posbit,0)); + newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),posbit-1,0)); emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key)); ifx->generated = 1; @@ -5654,16 +5662,29 @@ static void genAnd (iCode *ic, iCode *ifx) pic14_emitcode("setb","c"); while(sizel--){ if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){ - MOVA( aopGet(AOP(left),offset,FALSE,FALSE)); + mov2w( AOP(left), offset); // byte == 2^n ? - if((posbit = isLiteralBit(bytelit)) != 0) + if((posbit = isLiteralBit(bytelit)) != 0) { + emitpcode(rIfx.condition ? POC_BTFSC : POC_BTFSS, // XXX: or the other way round? + newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),posbit - 1, 0)); pic14_emitcode("jb","acc.%d,%05d_DS_",(posbit-1)&0x07,tlbl->key+100); + } else{ + emitpcode(POC_ANDLW, newpCodeOpLit(bytelit & 0x0ff)); + if (rIfx.condition) emitSKPZ; + else emitSKPNZ; + if(bytelit != 0x0FFL) + { pic14_emitcode("anl","a,%s", aopGet(AOP(right),offset,FALSE,TRUE)); + } pic14_emitcode("jnz","%05d_DS_",tlbl->key+100); } + + emitpcode(POC_GOTO, popGetLabel(rIfx.lbl->key)); + ifx->generated = 1; + } offset++; } diff --git a/src/pic/pcode.c b/src/pic/pcode.c index c1dd7d39..4067610b 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -4607,9 +4607,13 @@ static int BankSelect(pCodeInstruction *pci, int cur_bank, regs *reg) #if 1 /* Always insert BANKSELs rather than try to be clever: * Too many bugs in optimized banksels... */ + static PIC_device *pic; + if (!pic) pic = pic14_getPIC(); // possible optimizations: // * do not emit BANKSELs for SFRs that are present in all banks (bankmsk == regmap for this register) + if (reg && pic && ((reg->alias & pic->bankMask) == pic->bankMask)) return 'L'; + insertBankSel(pci, reg->name); // Let linker choose the bank selection return 'L'; #else -- 2.47.2