2004-03-03 Hans Dorn <hjdorn AT users.sourceforge.net>
authorhjdorn <hjdorn@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 3 Mar 2004 23:22:31 +0000 (23:22 +0000)
committerhjdorn <hjdorn@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 3 Mar 2004 23:22:31 +0000 (23:22 +0000)
* 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

ChangeLog
src/pic16/gen.c

index 09d4f04732926ed3f43174a54688465746f82a65..47c6e48e2b859690afaa986571d06ada8c913832 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-03-03 Hans Dorn <hjdorn AT users.sourceforge.net>
+
+       * src/pic16/gen.c (gencjne): fixed for right=REG / left=LIT
+
 2004-02-03 Vangelis Rokas <vrokas AT otenet.gr>
 
        * src/pic16/ralloc.c (newReg): fixed bug #908929
index 60e92e4f7672e4388260afaf384ba870231e2bf9..95afe3928a37bb0e41b8b05c804ca20f221b5d78 100644 (file)
@@ -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)