From: hjdorn Date: Wed, 3 Mar 2004 23:22:31 +0000 (+0000) Subject: 2004-03-03 Hans Dorn X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=db99733b50b2a32504ff0823c378e81046a4cef9;p=fw%2Fsdcc 2004-03-03 Hans Dorn * src/pic16/gen.c (gencjne): fixed for right=REG / left=LIT git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3244 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 09d4f047..47c6e48e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-03-03 Hans Dorn + + * src/pic16/gen.c (gencjne): fixed for right=REG / left=LIT + 2004-02-03 Vangelis Rokas * src/pic16/ralloc.c (newReg): fixed bug #908929 diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 60e92e4f..95afe392 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -5149,15 +5149,18 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) int res_offset = 0; /* the result may be a different size then left or right */ int res_size = AOP_SIZE(result); resolvedIfx rIfx; - symbol *lbl; + symbol *lbl, *lbl_done; unsigned long lit = 0L; + int preserve_result = 0; /* don't touch result before we are done, if left/right == result */ + DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); DEBUGpic16_pic16_AopType(__LINE__,left,right,result); if(result) DEBUGpic16_emitcode ("; ***","%s %d result is not null",__FUNCTION__,__LINE__); resolveIfx(&rIfx,ifx); lbl = newiTempLabel(NULL); + lbl_done = newiTempLabel(NULL); /* if the left side is a literal or @@ -5172,13 +5175,24 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) if(AOP_TYPE(right) == AOP_LIT) lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit); + if ( regsInCommon(left, result) || regsInCommon(right, result) ) + preserve_result = 1; + + if(result && !preserve_result) + { + int i; + for(i = 0; i < AOP_SIZE(result); i++) + pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),i)); + } + + /* if the right side is a literal then anything goes */ if (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR ) { switch(size) { case 2: genc16bit2lit(left, lit, 0); - emitSKPNZ; + emitSKPZ; pic16_emitpcode(POC_GOTO,pic16_popGetLabel(lbl->key)); break; default: @@ -5191,7 +5205,7 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) pic16_emitpcode(POC_MOVF,pic16_popGet(AOP(left),offset)); } - emitSKPNZ; + emitSKPZ; pic16_emitpcode(POC_GOTO,pic16_popGetLabel(lbl->key)); offset++; if(res_offset < res_size-1) @@ -5212,7 +5226,7 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) int lbl_key = lbl->key; if(result) { - pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),res_offset)); + // pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),res_offset)); //pic16_emitpcode(POC_INCF,pic16_popGet(AOP(result),res_offset)); }else { DEBUGpic16_emitcode ("; ***","%s %d -- ERROR",__FUNCTION__,__LINE__); @@ -5220,7 +5234,7 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) __FUNCTION__,__LINE__); return; } - + /* switch(size) { */ /* case 2: */ /* genc16bit2lit(left, lit, 0); */ @@ -5244,8 +5258,8 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) break; case 1: pic16_emitpcode(POC_DECFSZW,pic16_popGet(AOP(left),offset)); - pic16_emitpcode(POC_INCF,pic16_popGet(AOP(result),res_offset)); - //pic16_emitpcode(POC_GOTO,pic16_popGetLabel(lbl->key)); + //pic16_emitpcode(POC_INCF,pic16_popGet(AOP(result),res_offset)); + pic16_emitpcode(POC_GOTO,pic16_popGetLabel(lbl->key)); emit_skip=0; break; case 0xff: @@ -5321,12 +5335,32 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) } } - pic16_emitpcode(POC_INCF,pic16_popGet(AOP(result),res_offset)); + if(result && preserve_result) + { + int i; + for(i = 0; i < AOP_SIZE(result); i++) + pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),i)); + } + + pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result), 0)); + + if(result && preserve_result) + pic16_emitpcode(POC_GOTO,pic16_popGetLabel(lbl_done->key)); + if(!rIfx.condition) pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rIfx.lbl->key)); pic16_emitpLabel(lbl->key); + if(result && preserve_result) + { + int i; + for(i = 0; i < AOP_SIZE(result); i++) + pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),i)); + + pic16_emitpLabel(lbl_done->key); + } + DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); if(ifx)