From: SourceForge.net <no...@so...> - 2004-09-11 08:49:18
|
Patches item #1025666, was opened at 2004-09-10 01:46 Message generated for change (Comment added) made by colwaar You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=300599&aid=1025666&group_id=599 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Aaron Colwell (colwaar) >Assigned to: Vangelis Rokas (vrokas) Summary: PIC16 genAnd logic for conditionals Initial Comment: Here is a patch that allows the compiler to generate proper code for the following conditionals char foo(int val) { char tmp = 0; if (val & 0xff01) { tmp = 1; } else if (val & 0x42) { tmp = 2; } else if (val & 0x6262) { tmp = 3; } return tmp; } Index: gen.c ========================================== ========================= RCS file: /cvsroot/sdcc/sdcc/src/pic16/gen.c,v retrieving revision 1.44 diff -u -r1.44 gen.c --- gen.c 1 Sep 2004 10:14:17 -0000 1.44 +++ gen.c 10 Sep 2004 08:30:22 -0000 @@ -6601,33 +6601,56 @@ } else { symbol *tlbl = newiTempLabel(NULL); int sizel = AOP_SIZE(left); + int know_W = -1; + if(size) - pic16_emitcode("setb","c"); + emitSETC; + while(sizel--){ if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){ - MOVA( pic16_aopGet(AOP (left),offset,FALSE,FALSE)); // byte == 2^n ? - if((posbit = isLiteralBit(bytelit)) != 0) - pic16_emitcode("jb","acc.%d,%05d_DS_", (posbit-1)&0x07,tlbl->key+100); + if((posbit = isLiteralBit(bytelit)) != 0) { + pic16_emitpcode(((rIfx.condition) ? POC_BTFSS : POC_BTFSC ), + pic16_newpCodeOpBit (pic16_aopGet(AOP(left), + offset,FALSE, + FALSE), + (posbit-1),0, PO_GPR_REGISTER)); + + pic16_emitpcode(POC_BRA, pic16_popGetLabel (tlbl->key)); + } else{ - if(bytelit != 0x0FFL) - pic16_emitcode("anl","a,%s", - pic16_aopGet(AOP (right),offset,FALSE,TRUE)); - pic16_emitcode("jnz","%05d_DS_",tlbl- >key+100); + if (bytelit == 0xff) { + pic16_emitpcode(POC_MOVF, pic16_popGet (AOP(left), offset)); + } + else { + if ((know_W == -1) || (bytelit != know_W)) { + pic16_emitpcode(POC_MOVLW, pic16_popGetLit(bytelit)); + know_W = bytelit; + } + pic16_emitpcode(POC_ANDWF,pic16_popGet (AOP(left),offset)); + } + + pic16_emitpcode(((rIfx.condition) ? POC_BZ : POC_BNZ), + pic16_popGetLabel(tlbl->key)); } } offset++; } + // bit = left & literal if(size){ - pic16_emitcode("clr","c"); - pic16_emitcode("","%05d_DS_:",tlbl->key+100); + emitCLRC; + pic16_emitpLabel(tlbl->key); } // if(left & literal) else{ - if(ifx) - jmpTrueOrFalse(ifx, tlbl); - goto release ; + if(ifx) { + pic16_emitpcode(POC_BRA, pic16_popGetLabel (rIfx.lbl->key)); + pic16_emitpLabel(tlbl->key); + + ifx->generated = 1; + } + goto release ; } } pic16_outBitC(result); ---------------------------------------------------------------------- >Comment By: Aaron Colwell (colwaar) Date: 2004-09-11 01:49 Message: Logged In: YES user_id=85078 There was a bug in the previous diff. Here is a new diff that works properly Index: gen.c ============================================== ===================== RCS file: /cvsroot/sdcc/sdcc/src/pic16/gen.c,v retrieving revision 1.44 diff -u -r1.44 gen.c --- gen.c 1 Sep 2004 10:14:17 -0000 1.44 +++ gen.c 11 Sep 2004 08:41:41 -0000 @@ -6601,33 +6601,52 @@ } else { symbol *tlbl = newiTempLabel(NULL); int sizel = AOP_SIZE(left); + if(size) - pic16_emitcode("setb","c"); + emitSETC; + while(sizel--){ if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){ - MOVA( pic16_aopGet(AOP (left),offset,FALSE,FALSE)); // byte == 2^n ? - if((posbit = isLiteralBit(bytelit)) != 0) - pic16_emitcode("jb","acc.%d,%05d_DS_",(posbit- 1)&0x07,tlbl->key+100); - else{ - if(bytelit != 0x0FFL) - pic16_emitcode("anl","a,%s", - pic16_aopGet(AOP (right),offset,FALSE,TRUE)); - pic16_emitcode("jnz","%05d_DS_",tlbl->key+100); + if((posbit = isLiteralBit(bytelit)) != 0) { + pic16_emitpcode(((rIfx.condition) ? POC_BTFSS : POC_BTFSC ), + pic16_newpCodeOpBit(pic16_aopGet (AOP(left), + offset,FALSE, + FALSE), + (posbit-1),0, PO_GPR_REGISTER)); + + pic16_emitpcode(POC_BRA, pic16_popGetLabel(tlbl- >key)); + } + else { + if (bytelit == 0xff) { + pic16_emitpcode(POC_MOVF, pic16_popGet(AOP (left), offset)); + } + else { + pic16_emitpcode(POC_MOVFW, pic16_popGet (AOP(left), offset)); + pic16_emitpcode(POC_ANDLW, pic16_popGetLit (bytelit)); + } + + pic16_emitpcode(((rIfx.condition) ? POC_BZ : POC_BNZ), + pic16_popGetLabel(tlbl->key)); } } offset++; } + // bit = left & literal if(size){ - pic16_emitcode("clr","c"); - pic16_emitcode("","%05d_DS_:",tlbl->key+100); + emitCLRC; + pic16_emitpLabel(tlbl->key); } // if(left & literal) else{ - if(ifx) - jmpTrueOrFalse(ifx, tlbl); - goto release ; + if(ifx) { + pic16_emitpcode(POC_BRA, pic16_popGetLabel (rIfx.lbl->key)); + pic16_emitpLabel(tlbl->key); + + ifx->generated = 1; + } + goto release ; } } pic16_outBitC(result); ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=300599&aid=1025666&group_id=599 |