Fixed shifts by varaibles. Added rotate test code to src/regression
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 May 2002 14:17:48 +0000 (14:17 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 May 2002 14:17:48 +0000 (14:17 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2018 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/genarith.c
src/pic/pcode.c
src/regression/inline.c [new file with mode: 0644]
src/regression/rotate6.c [new file with mode: 0644]
src/regression/rotate7.c [new file with mode: 0644]

index 77c064b1254910cce9b13f33ad8ddd2dc25ae1b8..8b4c6d57b988aa521bb38e47413fecf391e0b8b3 100644 (file)
@@ -6147,8 +6147,8 @@ static void shiftR1Left2ResultSigned (operand *left, int offl,
       emitpcode(POC_RRFW, popGet(AOP(left),offl));
       emitpcode(POC_MOVWF, popGet(AOP(result),offr));
     }
-    emitpcode(POC_RLFW, popGet(AOP(result),offl));
-    emitpcode(POC_RRF,  popGet(AOP(result),offl));
+    emitpcode(POC_RLFW, popGet(AOP(result),offr));
+    emitpcode(POC_RRF,  popGet(AOP(result),offr));
 
     break;
 
@@ -6181,7 +6181,7 @@ static void shiftR1Left2ResultSigned (operand *left, int offl,
     if(same) {
       emitpcode(POC_SWAPF,  popGet(AOP(result),offr));
     } else {
-      emitpcode(POC_SWAPFW,  popGet(AOP(result),offr));
+      emitpcode(POC_SWAPFW,  popGet(AOP(left),offl));
       emitpcode(POC_MOVWF,  popGet(AOP(result),offr));
     }
     emitpcode(POC_RRFW,   popGet(AOP(result),offr));
@@ -6189,17 +6189,14 @@ static void shiftR1Left2ResultSigned (operand *left, int offl,
     emitpcode(POC_BTFSC,  newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
     emitpcode(POC_IORLW,  popGetLit(0xf8));
     emitpcode(POC_MOVWF,  popGet(AOP(result),offr));
-
-
-
     break;
 
   case 6:
     if(same) {
       emitpcode(POC_MOVLW, popGetLit(0x00));
-      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
       emitpcode(POC_MOVLW, popGetLit(0xfe));
-      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),6,0));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),6,0));
       emitpcode(POC_IORLW, popGetLit(0x01));
       emitpcode(POC_MOVWF, popGet(AOP(result),offr));
     } else {
@@ -6398,7 +6395,7 @@ static void shiftL1Left2Result (operand *left, int offl,
 /* movLeft2Result - move byte from left to result                  */
 /*-----------------------------------------------------------------*/
 static void movLeft2Result (operand *left, int offl,
-                            operand *result, int offr, int sign)
+                            operand *result, int offr)
 {
   char *l;
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
@@ -6409,18 +6406,8 @@ static void movLeft2Result (operand *left, int offl,
       pic14_emitcode("mov","a,%s",l);
       aopPut(AOP(result),"a",offr);
     } else {
-      //if(!sign) {
       emitpcode(POC_MOVFW, popGet(AOP(left),offl));
       emitpcode(POC_MOVWF, popGet(AOP(result),offr));
-
-      //aopPut(AOP(result),l,offr);
-      //}else{
-      /* MSB sign in acc.7 ! */
-      //if(pic14_getDataSize(left) == offl+1){
-      //  pic14_emitcode("mov","a,%s",l);
-      //  aopPut(AOP(result),"a",offr);
-      //}
-      //}
     }
   }
 }
@@ -6570,7 +6557,7 @@ static void shiftR2Left2Result (operand *left, int offl,
     MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
     pic14_emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
   } else {
-    movLeft2Result(left,offl, result, offr, 0);
+    movLeft2Result(left,offl, result, offr);
     MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
   }
   /* a:x >> shCount (x = lsb(result))*/
@@ -6586,12 +6573,15 @@ static void shiftR2Left2Result (operand *left, int offl,
   case 1:
   case 2:
   case 3:
-    emitCLRC;
+    if(sign)
+      emitpcode(POC_RLFW,popGet(AOP(result),offr+MSB16));
+    else
+      emitCLRC;
+
     if(same) {
       emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
       emitpcode(POC_RRF,popGet(AOP(result),offr));
     } else {
-
       emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16));
       emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
       emitpcode(POC_RRFW, popGet(AOP(left),offl));
@@ -6599,7 +6589,10 @@ static void shiftR2Left2Result (operand *left, int offl,
     }
 
     while(--shCount) {
-      emitCLRC;
+      if(sign)
+       emitpcode(POC_RLFW,popGet(AOP(result),offr+MSB16));
+      else
+       emitCLRC;
       emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
       emitpcode(POC_RRF,popGet(AOP(result),offr));
     }
@@ -6633,6 +6626,13 @@ static void shiftR2Left2Result (operand *left, int offl,
       emitpcode(POC_RRF, popGet(AOP(result),offr));
     }
 
+    if(sign) {
+      emitpcode(POC_MOVLW, popGetLit(0xf0 + (shCount-4)*8 ));
+      emitpcode(POC_BTFSC, 
+               newpCodeOpBit(aopGet(AOP(result),offr+MSB16,FALSE,FALSE),7-shCount,0));
+      emitpcode(POC_ADDWF, popGet(AOP(result),offr+MSB16));
+    }
+
     break;
 
   case 6:
@@ -6645,6 +6645,11 @@ static void shiftR2Left2Result (operand *left, int offl,
       emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
       emitpcode(POC_RLFW, popGet(AOP(result),offr));
       emitpcode(POC_ANDLW,popGetLit(0x03));
+      if(sign) {
+       emitpcode(POC_BTFSC, 
+                 newpCodeOpBit(aopGet(AOP(result),offr+MSB16,FALSE,FALSE),1,0));
+       emitpcode(POC_IORLW,popGetLit(0xfc));
+      }
       emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16));
       emitpcode(POC_XORWF,popGet(AOP(result),offr+MSB16));
       emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16));
@@ -6652,13 +6657,19 @@ static void shiftR2Left2Result (operand *left, int offl,
     } else {
       emitpcode(POC_RLFW, popGet(AOP(left),offl));
       emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
-      emitpcode(POC_RLFW, popGet(AOP(result),offl+MSB16));
+      emitpcode(POC_RLFW, popGet(AOP(left),offl+MSB16));
       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
-      emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
-      emitpcode(POC_RLF,  popGet(AOP(result),offr));
-      emitpcode(POC_RLFW, popGet(AOP(result),offr));
+      emitpcode(POC_RLFW,  popGet(AOP(result),offr+MSB16));
       emitpcode(POC_ANDLW,popGetLit(0x03));
+      if(sign) {
+       emitpcode(POC_BTFSC, 
+                 newpCodeOpBit(aopGet(AOP(result),offr+MSB16,FALSE,FALSE),0,0));
+       emitpcode(POC_IORLW,popGetLit(0xfc));
+      }
       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
+      emitpcode(POC_RLF,  popGet(AOP(result),offr));
+
+       
     }
 
     break;
@@ -6667,7 +6678,11 @@ static void shiftR2Left2Result (operand *left, int offl,
     emitpcode(POC_RLFW, popGet(AOP(left),offl+MSB16));
     emitpcode(POC_MOVWF,popGet(AOP(result),offr));
     emitpcode(POC_CLRF, popGet(AOP(result),offr+MSB16));
-    emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
+    if(sign) {
+      emitSKPNC;
+      emitpcode(POC_DECF, popGet(AOP(result),offr+MSB16));
+    } else 
+      emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
   }
 }
 
@@ -6731,7 +6746,7 @@ static void genlshTwo (operand *result,operand *left, int shCount)
             if (shCount)
                 shiftL1Left2Result(left, LSB, result, MSB16, shCount);
             else 
-                movLeft2Result(left, LSB, result, MSB16, 0);
+                movLeft2Result(left, LSB, result, MSB16);
         }
        emitpcode(POC_CLRF,popGet(AOP(result),LSB));
     }
@@ -6825,7 +6840,7 @@ static void genlshFour (operand *result, operand *left, int shCount)
             order of the destination */
             shiftL1Left2Result(left, LSB, result, MSB32, shCount);
         else
-            movLeft2Result(left, LSB, result, MSB32, 0);
+            movLeft2Result(left, LSB, result, MSB32);
         aopPut(AOP(result),zero,LSB);
         aopPut(AOP(result),zero,MSB16);
         aopPut(AOP(result),zero,MSB32);
@@ -6840,8 +6855,8 @@ static void genlshFour (operand *result, operand *left, int shCount)
         if (shCount)
             shiftL2Left2Result(left, LSB, result, MSB24, shCount);
         else {
-            movLeft2Result(left, MSB16, result, MSB32, 0);
-            movLeft2Result(left, LSB, result, MSB24, 0);
+            movLeft2Result(left, MSB16, result, MSB32);
+            movLeft2Result(left, LSB, result, MSB24);
         }
         aopPut(AOP(result),zero,MSB16);
         aopPut(AOP(result),zero,LSB);
@@ -6856,13 +6871,13 @@ static void genlshFour (operand *result, operand *left, int shCount)
             if(shCount)
                 shiftL1Left2Result(left, LSB, result, MSB16, shCount);
             else
-                movLeft2Result(left, LSB, result, MSB16, 0);
+                movLeft2Result(left, LSB, result, MSB16);
         }
         else{   /* size = 4 */
             if(shCount == 0){
-                movLeft2Result(left, MSB24, result, MSB32, 0);
-                movLeft2Result(left, MSB16, result, MSB24, 0);
-                movLeft2Result(left, LSB, result, MSB16, 0);
+                movLeft2Result(left, MSB24, result, MSB32);
+                movLeft2Result(left, MSB16, result, MSB24);
+                movLeft2Result(left, LSB, result, MSB16);
                 aopPut(AOP(result),zero,LSB);
             }
             else if(shCount == 1)
@@ -6917,7 +6932,7 @@ static void genLeftShiftLiteral (operand *left,
     /* I suppose that the left size >= result size */
     if(shCount == 0){
         while(size--){
-            movLeft2Result(left, size, result, size, 0);
+            movLeft2Result(left, size, result, size);
         }
     }
 
@@ -6977,130 +6992,168 @@ static void genMultiAsm( PIC_OPCODE poc, operand *reg, int size, int endian)
 /*-----------------------------------------------------------------*/
 static void genLeftShift (iCode *ic)
 {
-    operand *left,*right, *result;
-    int size, offset;
-    char *l;
-    symbol *tlbl , *tlbl1;
+  operand *left,*right, *result;
+  int size, offset;
+  char *l;
+  symbol *tlbl , *tlbl1;
+  pCodeOp *pctemp;
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-    right = IC_RIGHT(ic);
-    left  = IC_LEFT(ic);
-    result = IC_RESULT(ic);
+  right = IC_RIGHT(ic);
+  left  = IC_LEFT(ic);
+  result = IC_RESULT(ic);
 
-    aopOp(right,ic,FALSE);
+  aopOp(right,ic,FALSE);
 
-    /* if the shift count is known then do it 
-    as efficiently as possible */
-    if (AOP_TYPE(right) == AOP_LIT) {
-        genLeftShiftLiteral (left,right,result,ic);
-        return ;
-    }
+  /* if the shift count is known then do it 
+     as efficiently as possible */
+  if (AOP_TYPE(right) == AOP_LIT) {
+    genLeftShiftLiteral (left,right,result,ic);
+    return ;
+  }
 
-    /* shift count is unknown then we have to form 
-    a loop get the loop count in B : Note: we take
-    only the lower order byte since shifting
-    more that 32 bits make no sense anyway, ( the
-    largest size of an object can be only 32 bits ) */  
+  /* shift count is unknown then we have to form 
+     a loop get the loop count in B : Note: we take
+     only the lower order byte since shifting
+     more that 32 bits make no sense anyway, ( the
+     largest size of an object can be only 32 bits ) */  
 
     
-    aopOp(left,ic,FALSE);
-    aopOp(result,ic,FALSE);
+  aopOp(left,ic,FALSE);
+  aopOp(result,ic,FALSE);
 
-    /* now move the left to the result if they are not the
-    same */
-    if (!pic14_sameRegs(AOP(left),AOP(result)) && 
-        AOP_SIZE(result) > 1) {
+  /* now move the left to the result if they are not the
+     same */
+  if (!pic14_sameRegs(AOP(left),AOP(result)) && 
+      AOP_SIZE(result) > 1) {
 
-        size = AOP_SIZE(result);
-        offset=0;
-        while (size--) {
-            l = aopGet(AOP(left),offset,FALSE,TRUE);
-            if (*l == '@' && (IS_AOP_PREG(result))) {
+    size = AOP_SIZE(result);
+    offset=0;
+    while (size--) {
+      l = aopGet(AOP(left),offset,FALSE,TRUE);
+      if (*l == '@' && (IS_AOP_PREG(result))) {
 
-                pic14_emitcode("mov","a,%s",l);
-                aopPut(AOP(result),"a",offset);
-            } else
-                aopPut(AOP(result),l,offset);
-            offset++;
-        }
+       pic14_emitcode("mov","a,%s",l);
+       aopPut(AOP(result),"a",offset);
+      } else {
+       emitpcode(POC_MOVFW,  popGet(AOP(left),offset));
+       emitpcode(POC_MOVWF,  popGet(AOP(result),offset));
+       //aopPut(AOP(result),l,offset);
+      }
+      offset++;
     }
+  }
 
-    size = AOP_SIZE(result);
+  size = AOP_SIZE(result);
 
-    /* if it is only one byte then */
-    if (size == 1) {
-      if(optimized_for_speed) {
-       emitpcode(POC_SWAPFW, popGet(AOP(left),0));
-       emitpcode(POC_ANDLW,  popGetLit(0xf0));
-       emitpcode(POC_BTFSS,  newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),2,0));
+  /* if it is only one byte then */
+  if (size == 1) {
+    if(optimized_for_speed) {
+      emitpcode(POC_SWAPFW, popGet(AOP(left),0));
+      emitpcode(POC_ANDLW,  popGetLit(0xf0));
+      emitpcode(POC_BTFSS,  newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),2,0));
+      emitpcode(POC_MOVFW,  popGet(AOP(left),0));
+      emitpcode(POC_MOVWF,  popGet(AOP(result),0));
+      emitpcode(POC_BTFSS,  newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),0,0));
+      emitpcode(POC_ADDWF,  popGet(AOP(result),0));
+      emitpcode(POC_RLFW,   popGet(AOP(result),0));
+      emitpcode(POC_ANDLW,  popGetLit(0xfe));
+      emitpcode(POC_ADDFW,  popGet(AOP(result),0));
+      emitpcode(POC_BTFSC,  newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),1,0));
+      emitpcode(POC_ADDWF,  popGet(AOP(result),0));
+    } else {
+
+      tlbl = newiTempLabel(NULL);
+      if (!pic14_sameRegs(AOP(left),AOP(result))) {
        emitpcode(POC_MOVFW,  popGet(AOP(left),0));
        emitpcode(POC_MOVWF,  popGet(AOP(result),0));
-       emitpcode(POC_BTFSS,  newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),0,0));
-       emitpcode(POC_ADDWF,  popGet(AOP(result),0));
-       emitpcode(POC_RLFW,   popGet(AOP(result),0));
-       emitpcode(POC_ANDLW,  popGetLit(0xfe));
-       emitpcode(POC_ADDFW,  popGet(AOP(result),0));
-       emitpcode(POC_BTFSC,  newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),1,0));
-       emitpcode(POC_ADDWF,  popGet(AOP(result),0));
-      } else {
-
-       tlbl = newiTempLabel(NULL);
-       if (!pic14_sameRegs(AOP(left),AOP(result))) {
-         emitpcode(POC_MOVFW,  popGet(AOP(left),0));
-         emitpcode(POC_MOVWF,  popGet(AOP(result),0));
-       }
-
-       emitpcode(POC_COMFW,  popGet(AOP(right),0));
-       emitpcode(POC_RRF,    popGet(AOP(result),0));
-       emitpLabel(tlbl->key);
-       emitpcode(POC_RLF,    popGet(AOP(result),0));
-       emitpcode(POC_ADDLW,  popGetLit(1));
-       emitSKPC;
-       emitpcode(POC_GOTO,popGetLabel(tlbl->key));
       }
-      goto release ;
-    }
-    
-    if (pic14_sameRegs(AOP(left),AOP(result))) {
 
-      tlbl = newiTempLabel(NULL);
       emitpcode(POC_COMFW,  popGet(AOP(right),0));
-      genMultiAsm(POC_RRF, result, size,1);
+      emitpcode(POC_RRF,    popGet(AOP(result),0));
       emitpLabel(tlbl->key);
-      genMultiAsm(POC_RLF, result, size,0);
+      emitpcode(POC_RLF,    popGet(AOP(result),0));
       emitpcode(POC_ADDLW,  popGetLit(1));
       emitSKPC;
       emitpcode(POC_GOTO,popGetLabel(tlbl->key));
-      goto release;
     }
+    goto release ;
+  }
+    
+  if (pic14_sameRegs(AOP(left),AOP(result))) {
 
     tlbl = newiTempLabel(NULL);
-    offset = 0 ;   
-    tlbl1 = newiTempLabel(NULL);
+    emitpcode(POC_COMFW,  popGet(AOP(right),0));
+    genMultiAsm(POC_RRF, result, size,1);
+    emitpLabel(tlbl->key);
+    genMultiAsm(POC_RLF, result, size,0);
+    emitpcode(POC_ADDLW,  popGetLit(1));
+    emitSKPC;
+    emitpcode(POC_GOTO,popGetLabel(tlbl->key));
+    goto release;
+  }
 
-    reAdjustPreg(AOP(result));    
+  //tlbl = newiTempLabel(NULL);
+  //offset = 0 ;   
+  //tlbl1 = newiTempLabel(NULL);
+
+  //reAdjustPreg(AOP(result));    
     
-    pic14_emitcode("sjmp","%05d_DS_",tlbl1->key+100); 
-    pic14_emitcode("","%05d_DS_:",tlbl->key+100);    
-    l = aopGet(AOP(result),offset,FALSE,FALSE);
-    MOVA(l);
-    pic14_emitcode("add","a,acc");         
-    aopPut(AOP(result),"a",offset++);
-    while (--size) {
-        l = aopGet(AOP(result),offset,FALSE,FALSE);
-        MOVA(l);
-        pic14_emitcode("rlc","a");         
-        aopPut(AOP(result),"a",offset++);
-    }
-    reAdjustPreg(AOP(result));
+  //pic14_emitcode("sjmp","%05d_DS_",tlbl1->key+100); 
+  //pic14_emitcode("","%05d_DS_:",tlbl->key+100);    
+  //l = aopGet(AOP(result),offset,FALSE,FALSE);
+  //MOVA(l);
+  //pic14_emitcode("add","a,acc");         
+  //aopPut(AOP(result),"a",offset++);
+  //while (--size) {
+  //  l = aopGet(AOP(result),offset,FALSE,FALSE);
+  //  MOVA(l);
+  //  pic14_emitcode("rlc","a");         
+  //  aopPut(AOP(result),"a",offset++);
+  //}
+  //reAdjustPreg(AOP(result));
+
+  //pic14_emitcode("","%05d_DS_:",tlbl1->key+100);
+  //pic14_emitcode("djnz","b,%05d_DS_",tlbl->key+100);
 
-    pic14_emitcode("","%05d_DS_:",tlbl1->key+100);
-    pic14_emitcode("djnz","b,%05d_DS_",tlbl->key+100);
-release:
-    freeAsmop (right,NULL,ic,TRUE);
-    freeAsmop(left,NULL,ic,TRUE);
-    freeAsmop(result,NULL,ic,TRUE);
+
+  tlbl = newiTempLabel(NULL);
+  tlbl1= newiTempLabel(NULL);
+
+  size = AOP_SIZE(result);
+  offset = 1;
+
+  pctemp = popGetTempReg();  /* grab a temporary working register. */
+
+  emitpcode(POC_MOVFW, popGet(AOP(right),0));
+
+  /* offset should be 0, 1 or 3 */
+  emitpcode(POC_ANDLW, popGetLit(0x07 + ((offset&3) << 3)));
+  emitSKPNZ;
+  emitpcode(POC_GOTO,  popGetLabel(tlbl1->key));
+
+  emitpcode(POC_MOVWF, pctemp);
+
+
+  emitpLabel(tlbl->key);
+
+  emitCLRC;
+  emitpcode(POC_RLF,  popGet(AOP(result),0));
+  while(--size)
+    emitpcode(POC_RLF,   popGet(AOP(result),offset++));
+
+  emitpcode(POC_DECFSZ,  pctemp);
+  emitpcode(POC_GOTO,popGetLabel(tlbl->key));
+  emitpLabel(tlbl1->key);
+
+  popReleaseTempReg(pctemp);
+
+
+ release:
+  freeAsmop (right,NULL,ic,TRUE);
+  freeAsmop(left,NULL,ic,TRUE);
+  freeAsmop(result,NULL,ic,TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -7127,7 +7180,7 @@ static void genrshTwo (operand *result,operand *left,
       shiftR1Left2Result(left, MSB16, result, LSB,
                         shCount, sign);
     else
-      movLeft2Result(left, MSB16, result, LSB, sign);
+      movLeft2Result(left, MSB16, result, LSB);
 
     emitpcode(POC_CLRF,popGet(AOP(result),MSB16));
 
@@ -7182,56 +7235,57 @@ static void shiftRLong (operand *left, int offl,
 static void genrshFour (operand *result, operand *left,
                         int shCount, int sign)
 {
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    /* if shifting more that 3 bytes */
-    if(shCount >= 24 ) {
-        shCount -= 24;
-        if(shCount)
-            shiftR1Left2Result(left, MSB32, result, LSB, shCount, sign);
-        else
-            movLeft2Result(left, MSB32, result, LSB, sign);
-        addSign(result, MSB16, sign);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  /* if shifting more that 3 bytes */
+  if(shCount >= 24 ) {
+    shCount -= 24;
+    if(shCount)
+      shiftR1Left2Result(left, MSB32, result, LSB, shCount, sign);
+    else
+      movLeft2Result(left, MSB32, result, LSB);
+
+    addSign(result, MSB16, sign);
+  }
+  else if(shCount >= 16){
+    shCount -= 16;
+    if(shCount)
+      shiftR2Left2Result(left, MSB24, result, LSB, shCount, sign);
+    else{
+      movLeft2Result(left, MSB24, result, LSB);
+      movLeft2Result(left, MSB32, result, MSB16);
     }
-    else if(shCount >= 16){
-        shCount -= 16;
-        if(shCount)
-            shiftR2Left2Result(left, MSB24, result, LSB, shCount, sign);
-        else{
-            movLeft2Result(left, MSB24, result, LSB, 0);
-            movLeft2Result(left, MSB32, result, MSB16, sign);
-        }
-        addSign(result, MSB24, sign);
+    addSign(result, MSB24, sign);
+  }
+  else if(shCount >= 8){
+    shCount -= 8;
+    if(shCount == 1)
+      shiftRLong(left, MSB16, result, sign);
+    else if(shCount == 0){
+      movLeft2Result(left, MSB16, result, LSB);
+      movLeft2Result(left, MSB24, result, MSB16);
+      movLeft2Result(left, MSB32, result, MSB24);
+      addSign(result, MSB32, sign);
     }
-    else if(shCount >= 8){
-        shCount -= 8;
-        if(shCount == 1)
-            shiftRLong(left, MSB16, result, sign);
-        else if(shCount == 0){
-            movLeft2Result(left, MSB16, result, LSB, 0);
-            movLeft2Result(left, MSB24, result, MSB16, 0);
-            movLeft2Result(left, MSB32, result, MSB24, sign);
-            addSign(result, MSB32, sign);
-        }
-        else{
-            shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
-            shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
-            /* the last shift is signed */
-            shiftR1Left2Result(left, MSB32, result, MSB24, shCount, sign);
-            addSign(result, MSB32, sign);
-        }
+    else{
+      shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
+      shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
+      /* the last shift is signed */
+      shiftR1Left2Result(left, MSB32, result, MSB24, shCount, sign);
+      addSign(result, MSB32, sign);
     }
-    else{   /* 1 <= shCount <= 7 */
-        if(shCount <= 2){
-            shiftRLong(left, LSB, result, sign);
-            if(shCount == 2)
-                shiftRLong(result, LSB, result, sign);
-        }
-        else{
-            shiftR2Left2Result(left, LSB, result, LSB, shCount, 0);
-            shiftLLeftOrResult(left, MSB24, result, MSB16, 8 - shCount);
-            shiftR2Left2Result(left, MSB24, result, MSB24, shCount, sign);
-        }
+  }
+  else{   /* 1 <= shCount <= 7 */
+    if(shCount <= 2){
+      shiftRLong(left, LSB, result, sign);
+      if(shCount == 2)
+       shiftRLong(result, LSB, result, sign);
     }
+    else{
+      shiftR2Left2Result(left, LSB, result, LSB, shCount, 0);
+      shiftLLeftOrResult(left, MSB24, result, MSB16, 8 - shCount);
+      shiftR2Left2Result(left, MSB24, result, MSB24, shCount, sign);
+    }
+  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -7243,55 +7297,75 @@ static void genRightShiftLiteral (operand *left,
                                   iCode *ic,
                                   int sign)
 {    
-    int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
-    int size;
+  int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
+  int lsize,res_size;
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    freeAsmop(right,NULL,ic,TRUE);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  freeAsmop(right,NULL,ic,TRUE);
 
-    aopOp(left,ic,FALSE);
-    aopOp(result,ic,FALSE);
+  aopOp(left,ic,FALSE);
+  aopOp(result,ic,FALSE);
 
 #if VIEW_SIZE
-    pic14_emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
-             AOP_SIZE(left));
+  pic14_emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
+                AOP_SIZE(left));
 #endif
 
-    size = pic14_getDataSize(left);
-    /* test the LEFT size !!! */
+  lsize = pic14_getDataSize(left);
+  res_size = pic14_getDataSize(result);
+  /* test the LEFT size !!! */
 
-    /* I suppose that the left size >= result size */
-    if(shCount == 0){
-        size = pic14_getDataSize(result);
-        while(size--)
-            movLeft2Result(left, size, result, size, 0);
-    }
+  /* I suppose that the left size >= result size */
+  if(shCount == 0){
+    while(res_size--)
+      movLeft2Result(left, lsize, result, res_size);
+  }
 
-    else if(shCount >= (size * 8)){
-        if(sign)
-            /* get sign in acc.7 */
-            MOVA(aopGet(AOP(left),size-1,FALSE,FALSE));
-        addSign(result, LSB, sign);
-    } else{
-        switch (size) {
-            case 1:
-                genrshOne (result,left,shCount,sign);
-                break;
+  else if(shCount >= (lsize * 8)){
 
-            case 2:
-                genrshTwo (result,left,shCount,sign);
-                break;
+    if(res_size == 1) {
+      emitpcode(POC_CLRF, popGet(AOP(result),LSB));
+      if(sign) {
+       emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),lsize-1,FALSE,FALSE),7,0));
+       emitpcode(POC_DECF, popGet(AOP(result),LSB));
+      }
+    } else {
 
-            case 4:
-                genrshFour (result,left,shCount,sign);
-                break;
-            default :
-                break;
-        }
+      if(sign) {
+       emitpcode(POC_MOVLW, popGetLit(0));
+       emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),lsize-1,FALSE,FALSE),7,0));
+       emitpcode(POC_MOVLW, popGetLit(0xff));
+       while(res_size--)
+         emitpcode(POC_MOVWF, popGet(AOP(result),res_size));
+
+      } else {
+
+       while(res_size--)
+         emitpcode(POC_CLRF, popGet(AOP(result),res_size));
+      }
+    }
+  } else {
 
-        freeAsmop(left,NULL,ic,TRUE);
-        freeAsmop(result,NULL,ic,TRUE);
+    switch (res_size) {
+    case 1:
+      genrshOne (result,left,shCount,sign);
+      break;
+
+    case 2:
+      genrshTwo (result,left,shCount,sign);
+      break;
+
+    case 4:
+      genrshFour (result,left,shCount,sign);
+      break;
+    default :
+      break;
     }
+
+  }
+
+  freeAsmop(left,NULL,ic,TRUE);
+  freeAsmop(result,NULL,ic,TRUE);
 }
 
 /*-----------------------------------------------------------------*/
index 1741ad978be83da47c3551c1e7df64ca41ed8027..da50b903b5cc24fd1a94d24e5521841dba2021ce 100644 (file)
@@ -1104,22 +1104,33 @@ bool genMinusDec (iCode *ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* addSign - complete with sign                                    */
+/* addSign - propogate sign bit to higher bytes                    */
 /*-----------------------------------------------------------------*/
 void addSign(operand *result, int offset, int sign)
 {
-    int size = (pic14_getDataSize(result) - offset);
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    if(size > 0){
-        if(sign){
-            pic14_emitcode("rlc","a");
-            pic14_emitcode("subb","a,acc");
-            while(size--)
-                aopPut(AOP(result),"a",offset++); 
-        } else
-            while(size--)
-                aopPut(AOP(result),"#0",offset++);
-    }
+  int size = (pic14_getDataSize(result) - offset);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+  if(size > 0){
+    if(sign && offset) {
+
+      if(size == 1) {
+       emitpcode(POC_CLRF,popGet(AOP(result),offset));
+       emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(result),offset-1,FALSE,FALSE),7,0));
+       emitpcode(POC_DECF, popGet(AOP(result),offset));
+      } else {
+
+       emitpcode(POC_MOVLW, popGetLit(0));
+       emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(result),offset-1,FALSE,FALSE),7,0));
+       emitpcode(POC_MOVLW, popGetLit(0xff));
+       while(size--)
+         emitpcode(POC_MOVWF, popGet(AOP(result),size));
+
+      }
+    } else
+      while(size--)
+       emitpcode(POC_CLRF,popGet(AOP(result),offset++));
+  }
 }
 
 /*-----------------------------------------------------------------*/
index 2c0c54268b950e732c0bf4738d823b3a50140ea9..9249f813bbde8c79b2d45cd1c0912a87135f5223 100644 (file)
@@ -70,7 +70,7 @@ static hTab *pic14pCodePeepCommandsHash = NULL;
 
 
 static pFile *the_pFile = NULL;
-static int peepOptimizing = 1;
+static int peepOptimizing = 0;
 static int GpCodeSequenceNumber = 1;
 static int GpcFlowSeq = 1;
 
diff --git a/src/regression/inline.c b/src/regression/inline.c
new file mode 100644 (file)
index 0000000..893441e
--- /dev/null
@@ -0,0 +1,38 @@
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+unsigned char test_tris=0;
+
+#define PORTA_ADR  5
+#define PORTB_ADR  6
+#define TRISA_ADR  0x85
+#define TRISB_ADR  0x86
+
+data at TRISA_ADR unsigned char  TRISA;
+
+void done(void)
+{
+
+  dummy++;
+
+}
+void main(void)
+{
+  dummy = 0;
+
+  TRISA = 0x0f;
+
+  _asm
+    BSF   STATUS,RP0
+    MOVF  TRISA,W
+    BCF   STATUS,RP0
+    MOVWF _test_tris
+  _endasm;
+
+  if(test_tris != 0x0f)
+    failures++;
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/rotate6.c b/src/regression/rotate6.c
new file mode 100644 (file)
index 0000000..f0bebdd
--- /dev/null
@@ -0,0 +1,138 @@
+// Shift bytes left and right by a variable.
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+signed int aint0 = 0;
+signed int aint1 = 0;
+signed char achar0 = 0;
+signed char achar1 = 0;
+signed char achar2 = 0;
+signed char achar3 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void shift_right_var(void)
+{
+
+  achar0 >>= achar1;
+
+}
+
+void shift_left_var(void)
+{
+
+  achar0 <<= achar1;
+}
+
+void shift_int_left_var(void)
+{
+
+  aint0 <<= achar1;
+
+}
+
+void shift_int_right_var(void)
+{
+
+  aint0 >>= achar1;
+
+}
+
+void shift_int_right_var2(void)
+{
+
+  aint0 = aint1 >> achar1;
+
+}
+
+void shift_int_left_var2(void)
+{
+
+  aint0 = aint1 << achar1;
+
+}
+
+void main(void)
+{
+  char i;
+
+  achar0 = 1;
+  achar1 = 1;
+  shift_left_var();
+
+  if(achar0 !=2)
+    failures++;
+
+  achar0 = 1;
+  achar1 = 1;
+  achar2 = 1;
+  for(i=0; i<7; i++) {
+    shift_left_var();
+    achar2 <<= 1;
+
+    if(achar2 != achar0)
+      failures++;
+  }
+
+  achar1 = 4;
+  achar0 = 0xf0;
+  shift_right_var();
+  if(achar0 != 0xff)
+    failures++;
+
+  aint0 = 1;
+  aint1 = 1;
+  achar1 = 1;
+
+  for(i=0; i<15; i++) {
+    shift_int_left_var();
+    aint1 <<= 1;
+    if(aint0 != aint1)
+      failures++;
+  }
+
+  aint0 = 0x4000;
+  aint1 = 0x4000;
+
+  for(i=0; i<15; i++) {
+    shift_int_right_var();
+    aint1 >>= 1;
+    if(aint0 != aint1)
+      failures++;
+  }
+
+
+  aint0 = -0x4000;
+  aint1 = -0x4000;
+
+  for(i=0; i<15; i++) {
+    shift_int_right_var();
+    aint1 >>= 1;
+    if(aint0 != aint1)
+      failures++;
+  }
+
+  aint1 = 0xf000;
+  achar1 = 10;
+  shift_int_right_var2();
+
+  if(aint0 != 0xfffc)
+    failures++;
+
+  aint1 = aint0;
+  shift_int_left_var2();
+
+  if(aint0 != 0xf000)
+    failures++;
+
+  success=failures;
+  done();
+}
diff --git a/src/regression/rotate7.c b/src/regression/rotate7.c
new file mode 100644 (file)
index 0000000..c5a3dc2
--- /dev/null
@@ -0,0 +1,390 @@
+// Shift ints left and right
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+signed int aint0 = 0;
+signed int aint1 = 0;
+signed char achar0 = 0;
+signed char achar1 = 0;
+signed char achar2 = 0;
+signed char achar3 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void shift_int_left_1(void)
+{
+
+  aint0 <<= 1;
+
+}
+
+void shift_int_left_2(void)
+{
+
+  aint0 <<= 2;
+
+}
+
+void shift_int_left_3(void)
+{
+
+  aint0 <<= 3;
+
+}
+
+void shift_int_left_4(void)
+{
+
+  aint0 <<= 4;
+
+}
+
+void shift_int_left_5(void)
+{
+
+  aint0 <<= 5;
+
+}
+
+void shift_int_left_6(void)
+{
+
+  aint0 <<= 6;
+
+}
+
+void shift_int_left_7(void)
+{
+
+  aint0 <<= 7;
+
+}
+
+void shift_int_left_8(void)
+{
+
+  aint0 <<= 8;
+
+}
+
+void shift_int_left_9(void)
+{
+
+  aint0 <<= 9;
+
+}
+
+void shift_int_left_10(void)
+{
+
+  aint0 <<= 10;
+
+}
+
+void shift_int_left_11(void)
+{
+
+  aint0 <<= 11;
+
+}
+
+void shift_int_left_12(void)
+{
+
+  aint0 <<= 12;
+
+}
+
+void shift_int_left_13(void)
+{
+
+  aint0 <<= 13;
+
+}
+
+void shift_int_left_14(void)
+{
+
+  aint0 <<= 14;
+
+}
+
+void shift_int_left_15(void)
+{
+
+  aint0 <<= 15;
+
+}
+
+/*****************************************************/
+void shift_int_right_1(void)
+{
+  aint0 >>= 1;
+}
+
+void shift_int_right_2(void)
+{
+  aint0 >>= 2;
+}
+
+void shift_int_right_3(void)
+{
+  aint0 >>= 3;
+}
+
+void shift_int_right_4(void)
+{
+  aint0 >>= 4;
+}
+
+void shift_int_right_5(void)
+{
+  aint0 >>= 5;
+}
+
+void shift_int_right_6(void)
+{
+  aint0 >>= 6;
+}
+
+void shift_int_right_7(void)
+{
+  aint0 >>= 7;
+}
+
+void shift_int_right_8(void)
+{
+  aint0 >>= 8;
+}
+
+void shift_int_right_9(void)
+{
+  aint0 >>= 9;
+}
+
+void shift_int_right_10(void)
+{
+  aint0 >>= 10;
+}
+
+void shift_int_right_11(void)
+{
+  aint0 >>= 11;
+}
+
+void shift_int_right_12(void)
+{
+  aint0 >>= 12;
+}
+
+void shift_int_right_13(void)
+{
+  aint0 >>= 13;
+}
+
+void shift_int_right_14(void)
+{
+  aint0 >>= 14;
+}
+
+void shift_int_right_15(void)
+{
+  aint0 >>= 15;
+}
+
+/*****************************************************/
+void main(void)
+{
+  //char i;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_1();
+  if(aint0 != 0x579a)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_2();
+  if(aint0 != 0xaf34)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_3();
+  if(aint0 != 0x5e68)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_4();
+  if(aint0 != 0xbcd0)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_5();
+  if(aint0 != 0x79a0)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_6();
+  if(aint0 != 0xf340)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_7();
+  if(aint0 != 0xe680)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_8();
+  if(aint0 != 0xcd00)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_9();
+  if(aint0 != 0x9a00)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_10();
+  if(aint0 != 0x3400)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_11();
+  if(aint0 != 0x6800)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_12();
+  if(aint0 != 0xd000)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_13();
+  if(aint0 != 0xa000)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_14();
+  if(aint0 != 0x4000)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_left_15();
+  if(aint0 != 0x8000)
+    failures++;
+
+  /***********************/
+  aint0 = 0xabcd;
+
+  shift_int_right_1();
+  if(aint0 != 0xd5e6)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_2();
+  if(aint0 != 0xeaf3)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_3();
+  if(aint0 != 0xf579)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_4();
+  if(aint0 != 0xfabc)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_5();
+  if(aint0 != 0xfd5e)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_6();
+  if(aint0 != 0xfeaf)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_7();
+  if(aint0 != 0xff57)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_8();
+  if(aint0 != 0xffab)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_9();
+  if(aint0 != 0xffd5)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_10();
+  if(aint0 != 0xffea)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_11();
+  if(aint0 != 0xfff5)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_12();
+  if(aint0 != 0xfffa)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_13();
+  if(aint0 != 0xfffd)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_14();
+  if(aint0 != 0xfffe)
+    failures++;
+
+  aint0 = 0xabcd;
+
+  shift_int_right_15();
+  if(aint0 != -1)
+    failures++;
+
+  success=failures;
+  done();
+}