- signed/unsigned long comparisons now work.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 16 Oct 2001 15:51:45 +0000 (15:51 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 16 Oct 2001 15:51:45 +0000 (15:51 +0000)
 - compound compares with chars and ints work.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1410 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/genarith.c
src/regression/Makefile
src/regression/add3.c
src/regression/compare3.c
src/regression/compare4.c
src/regression/compare5.c [new file with mode: 0644]

index fcff2474ef887781b69d41d89c39b4903643271f..78b27bfbc3e98e48d71e88b06cb1e86c23bb3d1b 100644 (file)
@@ -71,6 +71,8 @@ static int max_key=0;
 unsigned int pic14aopLiteral (value *val, int offset);
 const char *AopType(short type);
 
+#define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff)
+
 /* this is the down and dirty file with all kinds of 
    kludgy & hacky stuff. This is what it is all about
    CODE GENERATION for a specific MCU . some of the
@@ -176,7 +178,7 @@ void DEBUGpic14_emitcode (char *inst,char *fmt, ...)
 
 static void emitpLabel(int key)
 {
-  addpCode2pBlock(pb,newpCodeLabel(key));
+  addpCode2pBlock(pb,newpCodeLabel(key+100+labelOffset));
 }
 
 void emitpcode(PIC_OPCODE poc, pCodeOp *pcop)
@@ -1535,7 +1537,9 @@ int pic14_getDataSize(operand *op)
 void pic14_outAcc(operand *result)
 {
     int size, offset;
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+    DEBUGpic14_emitcode ("; ***","%s  %d - Warning no code will be generated here",__FUNCTION__,__LINE__);
+
+#if 0
     size = pic14_getDataSize(result);
     if(size){
         aopPut(AOP(result),"a",0);
@@ -1546,6 +1550,7 @@ void pic14_outAcc(operand *result)
             aopPut(AOP(result),zero,offset++);
         }
     }
+#endif
 }
 
 /*-----------------------------------------------------------------*/
@@ -2392,7 +2397,7 @@ static void genFunction (iCode *ic)
 
     DEBUGpic14_emitcode ("; ***","%s  %d previous max_key=%d ",__FUNCTION__,__LINE__,max_key);
 
-    labelOffset += (max_key+1);
+    labelOffset += (max_key+2);
     max_key=0;
 
     _G.nRegsSaved = 0;
@@ -2783,7 +2788,7 @@ static void genLabel (iCode *ic)
     if (IC_LABEL(ic) == entryLabel)
         return ;
 
-    emitpLabel(IC_LABEL(ic)->key+100 + labelOffset);
+    emitpLabel(IC_LABEL(ic)->key);
     pic14_emitcode("","_%05d_DS_:",(IC_LABEL(ic)->key+100 + labelOffset));
 }
 
@@ -3429,50 +3434,60 @@ static void genCmp (operand *left,operand *right,
 
        lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
        //default:
-       while(size--) {
-         i = (lit >> (size*8)) & 0xff;
-         if(i == 0) {
-           emitpcode(POC_MOVFW, popGet(AOP(left),size,FALSE,FALSE));
-           pic14_emitcode("movf","%s,w",aopGet(AOP(left),size,FALSE,FALSE));
-           genSkipz(ifx,IC_TRUE(ifx) == NULL);
-         } else {
-           emitpcode(POC_MOVLW, popGetLit(i));
-           emitpcode(POC_SUBFW, popGet(AOP(left),size,FALSE,FALSE));
+/*     if( lit == 0 ){
+         emitpcode(POC_MOVFW, popGet(AOP(left),0,FALSE,FALSE));
+         while(--size) 
+           emitpcode(POC_IORFW, popGet(AOP(left),++offset,FALSE,FALSE));
 
-           pic14_emitcode("movlw","0x%x",i);
-           pic14_emitcode("subwf","%s,w",aopGet(AOP(left),size,FALSE,FALSE));
-           genSkipc(ifx,IC_TRUE(ifx) == NULL);
+         genSkipz(ifx,IC_TRUE(ifx) == NULL);
+       } else {
+*/
+         while(size--) {
+           i = (lit >> (size*8)) & 0xff;
+           if(i == 0) {
+             emitpcode(POC_MOVFW, popGet(AOP(left),size,FALSE,FALSE));
+             genSkipz(ifx,IC_TRUE(ifx) == NULL);
+           } else {
+             emitpcode(POC_MOVLW, popGetLit(i));
+             emitpcode(POC_SUBFW, popGet(AOP(left),size,FALSE,FALSE));
+             genSkipc(ifx,IC_TRUE(ifx) == NULL);
+           }
          }
-
-       }
+  //   }
        ifx->generated = 1;
        return;
       }
+
       if(AOP_TYPE(left) == AOP_LIT) {
 
        DEBUGpic14_emitcode(";left lit","%d",sign);
 
+       offset = 0;
        lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit))+1;
 
-       //default:
-       while(size--) {
-         i = (lit >> (size*8)) & 0xff;
-         if(i == 0) {
-           emitpcode(POC_MOVFW, popGet(AOP(right),size,FALSE,FALSE));
-           pic14_emitcode("movf","%s,w",aopGet(AOP(right),size,FALSE,FALSE));
-           genSkipz(ifx,IC_TRUE(ifx) != NULL);
-         } else if( i == 1 ) {
-           emitpcode(POC_DECFW, popGet(AOP(right),size,FALSE,FALSE));
-           pic14_emitcode("decf","%s,w",aopGet(AOP(right),size,FALSE,FALSE));
-           genSkipz(ifx,IC_TRUE(ifx) != NULL);
+       if( lit == 0 ){
+         emitpcode(POC_MOVFW, popGet(AOP(right),0,FALSE,FALSE));
+         while(--size)
+           emitpcode(POC_IORFW, popGet(AOP(right),++offset,FALSE,FALSE));
 
-         } else {
-           emitpcode(POC_MOVLW, popGetLit(i));
-           emitpcode(POC_SUBFW, popGet(AOP(right),size,FALSE,FALSE));
+         genSkipz(ifx,IC_TRUE(ifx) != NULL);
+       } else {
+
+         while(size--) {
+           i = (lit >> (size*8)) & 0xff;
+           if(i == 0) {
+             emitpcode(POC_MOVFW, popGet(AOP(right),size,FALSE,FALSE));
+             genSkipz(ifx,IC_TRUE(ifx) != NULL);
+           } else if( i == 1 ) {
+             emitpcode(POC_DECFW, popGet(AOP(right),size,FALSE,FALSE));
+             genSkipz(ifx,IC_TRUE(ifx) != NULL);
+
+           } else {
+             emitpcode(POC_MOVLW, popGetLit(i));
+             emitpcode(POC_SUBFW, popGet(AOP(right),size,FALSE,FALSE));
 
-           pic14_emitcode("movlw","0x%x",i);
-           pic14_emitcode("subwf","%s,w",aopGet(AOP(right),size,FALSE,FALSE));
-           genSkipc(ifx,IC_TRUE(ifx) != NULL);
+             genSkipc(ifx,IC_TRUE(ifx) != NULL);
+           }
          }
        }
        ifx->generated = 1;
@@ -3583,6 +3598,46 @@ static void genCmpLt (iCode *ic, iCode *ifx)
     freeAsmop(result,NULL,ic,TRUE); 
 }
 
+/*-----------------------------------------------------------------*/
+/* genc16bit2lit - compare a 16 bit value to a literal             */
+/*-----------------------------------------------------------------*/
+static void genc16bit2lit(operand *op, int lit, int offset)
+{
+  int i;
+
+  DEBUGpic14_emitcode ("; ***","%s  %d, lit = %d",__FUNCTION__,__LINE__,lit);
+  if( (lit&0xff) == 0) 
+    i=1;
+  else
+    i=0;
+
+  switch( BYTEofLONG(lit,i)) { 
+  case 0:
+    emitpcode(POC_MOVFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    break;
+  case 1:
+    emitpcode(POC_DECFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    break;
+  case 0xff:
+    emitpcode(POC_INCFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    break;
+  default:
+    emitpcode(POC_MOVFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    emitpcode(POC_XORLW,popGetLit(BYTEofLONG(lit,i)));
+  }
+  i ^= 1;
+
+  if(BYTEofLONG(lit,i)) {
+    emitpcode(POC_MOVLW,popGetLit(BYTEofLONG(lit,i)));
+    emitSKPNZ;
+    emitpcode(POC_XORFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+
+  }else {
+    emitpcode(POC_IORFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+  }
+
+}
+
 /*-----------------------------------------------------------------*/
 /* gencjneshort - compare and jump if not equal                    */
 /*-----------------------------------------------------------------*/
@@ -3608,18 +3663,33 @@ static void gencjneshort(operand *left, operand *right, symbol *lbl)
     /* 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;
+       pic14_emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
+       emitpcode(POC_GOTO,popGetLabel(lbl->key));
+       break;
+      default:
         while (size--) {
          if(lit & 0xff) {
+           emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
+           emitpcode(POC_XORLW,popGetLit(lit & 0xff));
            pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
            pic14_emitcode("xorlw","0x%x",lit & 0xff);
-         } else
+         } else {
+           emitpcode(POC_MOVF,popGet(AOP(left),offset,FALSE,FALSE));
            pic14_emitcode("movf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
+         }
 
          emitSKPNZ;
          pic14_emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
+         emitpcode(POC_GOTO,popGetLabel(lbl->key));
          offset++;
          lit >>= 8;
         }
+       break;
+      }
     }
 
     /* if the right side is in a register or in direct space or
@@ -3628,30 +3698,33 @@ static void gencjneshort(operand *left, operand *right, symbol *lbl)
              AOP_TYPE(right) == AOP_DIR || 
              (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
              (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) {
+      switch(size) {
+      case 2:
+       genc16bit2lit(left, lit, 0);
+       emitSKPNZ;
+       pic14_emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
+       emitpcode(POC_GOTO,popGetLabel(lbl->key));
+       break;
+      default:
         while (size--) {
          if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
             ( (lit & 0xff) != 0)) {
+           emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
+           emitpcode(POC_XORLW,popGetLit(lit & 0xff));
            pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
            pic14_emitcode("xorlw","0x%x",lit & 0xff);
            lit >>= 8;
-         } else
+         } else {
+           emitpcode(POC_MOVF,popGet(AOP(left),offset,FALSE,FALSE));
            pic14_emitcode("movf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
-
+         }
          emitSKPZ;
          pic14_emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
+         emitpcode(POC_GOTO,popGetLabel(lbl->key));
          offset++;
-/*
-            MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
-            if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
-               ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
-                pic14_emitcode("jnz","%05d_DS_",lbl->key+100);
-            else
-                pic14_emitcode("cjne","a,%s,%05d_DS_",
-                         aopGet(AOP(right),offset,FALSE,TRUE),
-                         lbl->key+100);
-            offset++;
-*/
         }
+       break;
+      }
     } else {
         /* right is a pointer reg need both a & b */
         while(size--) {
@@ -3680,6 +3753,12 @@ static void gencjne(operand *left, operand *right, symbol *lbl)
     pic14_emitcode("","%05d_DS_:",lbl->key+100);
     pic14_emitcode("clr","a");
     pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+
+    emitpLabel(lbl->key);
+    emitpLabel(tlbl->key);
+
+
+
 }
 
 
@@ -3693,6 +3772,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
     int size,offset=0;
 
     DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
     if(ifx)
       DEBUGpic14_emitcode ("; ifx is non-null","");
     else
@@ -3702,6 +3782,12 @@ static void genCmpEq (iCode *ic, iCode *ifx)
     aopOp((right=IC_RIGHT(ic)),ic,FALSE);
     aopOp((result=IC_RESULT(ic)),ic,TRUE);
 
+
+    DEBUGpic14_emitcode ("; ","result %s, left %s, right %s",
+                        AopType(AOP_TYPE(IC_RESULT(ic))),
+                        AopType(AOP_TYPE(IC_LEFT(ic))),
+                        AopType(AOP_TYPE(IC_RIGHT(ic))));
+
     size = max(AOP_SIZE(left),AOP_SIZE(right));
 
     /* if literal, literal on the right or 
@@ -3752,157 +3838,82 @@ static void genCmpEq (iCode *ic, iCode *ifx)
 
          /* They're not both bit variables. Is the right a literal? */
          if(AOP_TYPE(right) == AOP_LIT) {
-
            lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-           while (size--) {
+           
 
-             if(size >= 1) {
-               int l = lit & 0xff;
-               int h = (lit>>8) & 0xff;
-               int optimized=0;
-
-               /* Check special cases for integers */
-               switch(lit & 0xffff) {
-               case 0x0000:
-                 emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
-                 emitpcode(POC_IORFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-                 //pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 //pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                 genSkip(ifx,'z');
-                 optimized++;
-                 break;
-               case 0x0001:
-                 emitpcode(POC_DECFW,popGet(AOP(left),offset,FALSE,FALSE));
-                 emitpcode(POC_IORFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-                 pic14_emitcode("decf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                 genSkip(ifx,'z');
-                 optimized++;
-                 break;
-               case 0x0100:
-                 emitpcode(POC_DECFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-                 emitpcode(POC_IORFW,popGet(AOP(left),offset,FALSE,FALSE));
-                 pic14_emitcode("decf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                 pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 genSkip(ifx,'z');
-                 optimized++;
-                 break;
-               case 0x00ff:
-                 emitpcode(POC_INCFW,popGet(AOP(left),offset,FALSE,FALSE));
-                 emitpcode(POC_IORFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-                 pic14_emitcode("incf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                 genSkip(ifx,'z');
-                 optimized++;
-                 break;
-               case 0xff00:
-                 emitpcode(POC_INCFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-                 emitpcode(POC_IORFW,popGet(AOP(left),offset,FALSE,FALSE));
-                 pic14_emitcode("incf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                 pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 genSkip(ifx,'z');
-                 optimized++;
-                 break;
-               default:
-                 if(h == 0) {
-                   emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
-                   emitpcode(POC_XORLW,popGetLit(l));
-                   emitpcode(POC_IORFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-
-                   pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                   pic14_emitcode("xorlw","0x%x",l);
-                   pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                   optimized++;
-                   genSkip(ifx,'z');
-                 } else if (l == 0) {
-                   emitpcode(POC_MOVFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-                   emitpcode(POC_XORLW,popGetLit(h));
-                   emitpcode(POC_IORFW,popGet(AOP(left),offset,FALSE,FALSE));
-
-                   pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-                   pic14_emitcode("xorlw","0x%x",h);
-                   pic14_emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                   optimized++;
-                   genSkip(ifx,'z');
-                 } else {
-                   emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
-                   emitpcode(POC_XORLW,popGetLit(l));
-                   emitpcode(POC_MOVLW,popGetLit(h));
-                   emitSKPNZ;
-                   emitpcode(POC_XORFW,popGet(AOP(left),offset+1,FALSE,FALSE));
-/*
-                   pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                   pic14_emitcode("xorlw","0x%x",l);
-                   pic14_emitcode("movlw","0x%x",h);
-                   emitSKPZ;
-                   pic14_emitcode("xorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
-*/
-                   optimized++;
-                   genSkip(ifx,'z');
-                 }
+           switch(size) {
 
-               }
-               if(optimized) {
-                 size--;
-                 offset+=2;
-                 lit>>=16;
-
-                 continue;
-               }
-                 
-             }
-               
+           case 1:
              switch(lit & 0xff) {
              case 1:
                if ( IC_TRUE(ifx) ) {
-
-                 pic14_emitcode("decf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-
                  emitpcode(POC_DECFW,popGet(AOP(left),offset,FALSE,FALSE));
                  emitSKPNZ;
                  emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
-
-                 pic14_emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
                } else {
                  emitpcode(POC_DECFSZW,popGet(AOP(left),offset,FALSE,FALSE));
                  emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
-
-                 pic14_emitcode("decfsz","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 pic14_emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
                }
                break;
              case 0xff:
                if ( IC_TRUE(ifx) ) {
-                 pic14_emitcode("incf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-
                  emitpcode(POC_INCFW,popGet(AOP(left),offset,FALSE,FALSE));
                  emitSKPNZ;
                  emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
-
-                 pic14_emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
                } else {
                  emitpcode(POC_INCFSZW,popGet(AOP(left),offset,FALSE,FALSE));
                  emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
-
-                 pic14_emitcode("incfsz","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 pic14_emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
                }
                break;
              default:
                emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
-               //pic14_emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
                if(lit)
                  emitpcode(POC_XORLW,popGetLit(lit & 0xff));
-               //pic14_emitcode("xorlw","0x%x",lit & 0xff);
                genSkip(ifx,'z');
              }
 
 
-             //              pic14_emitcode("goto","_%05d_DS_",tlbl->key+100+labelOffset);
-             //pic14_emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);                
-             offset++;
-             lit >>= 8;
+             /* end of size == 1 */
+             break;
+             
+           case 2:
+             genc16bit2lit(left,lit,offset);
+             genSkip(ifx,'z');
+             break;
+             /* end of size == 2 */
+
+           default:
+             /* size is 4 */
+             if(lit==0) {
+               emitpcode(POC_MOVFW,popGet(AOP(left),0,FALSE,FALSE));
+               emitpcode(POC_IORFW,popGet(AOP(left),1,FALSE,FALSE));
+               emitpcode(POC_IORFW,popGet(AOP(left),2,FALSE,FALSE));
+               emitpcode(POC_IORFW,popGet(AOP(left),3,FALSE,FALSE));
+
+             } else {
+
+               /* search for patterns that can be optimized */
+
+               genc16bit2lit(left,lit,0);
+               lit >>= 16;
+               if(lit) {
+                 genSkipz(ifx,IC_TRUE(ifx) == NULL);
+                 //genSkip(ifx,'z');
+                 genc16bit2lit(left,lit,2);
+               } else {
+                 emitpcode(POC_IORFW,popGet(AOP(left),2,FALSE,FALSE));
+                 emitpcode(POC_IORFW,popGet(AOP(left),3,FALSE,FALSE));
+
+               }
+               
+             }
+
+             genSkip(ifx,'z');
            }
+         
+           ifx->generated = 1;
+           goto release ;
+           
 
          } else if(AOP_TYPE(right) == AOP_CRY ) {
            /* we know the left is not a bit, but that the right is */
@@ -3972,7 +3983,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
              offset++;
            }
            if(s>1 && IC_TRUE(ifx)) {
-             emitpLabel(tlbl->key+100+labelOffset);
+             emitpLabel(tlbl->key);
              pic14_emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);                
            }
          }
@@ -6328,7 +6339,7 @@ static void genLeftShift (iCode *ic)
 
        emitpcode(POC_COMFW,  popGet(AOP(right),0,FALSE,FALSE));
        emitpcode(POC_RRF,    popGet(AOP(result),0,FALSE,FALSE));
-       emitpLabel(tlbl->key+100+labelOffset);
+       emitpLabel(tlbl->key);
        emitpcode(POC_RLF,    popGet(AOP(result),0,FALSE,FALSE));
        emitpcode(POC_ADDLW,  popGetLit(1));
        emitSKPC;
@@ -6750,7 +6761,7 @@ static void genRightShift (iCode *ic)
 
        emitpcode(POC_COMFW,  popGet(AOP(right),0,FALSE,FALSE));
        emitpcode(POC_RLF,    popGet(AOP(result),0,FALSE,FALSE));
-       emitpLabel(tlbl->key+100+labelOffset);
+       emitpLabel(tlbl->key);
        emitpcode(POC_RRF,    popGet(AOP(result),0,FALSE,FALSE));
        emitpcode(POC_ADDLW,  popGetLit(1));
        emitSKPC;
@@ -8227,7 +8238,7 @@ static void genJumpTab (iCode *ic)
     emitSKPNC;
     emitpcode(POC_INCF, popCopyReg(&pc_pclath));
     emitpcode(POC_MOVWF, popCopyReg(&pc_pcl));
-    emitpLabel(jtab->key+100+labelOffset);
+    emitpLabel(jtab->key);
 
     freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
 
index 644311fd4b452acc47cc3498911f178b9183d157..99e3b661c4226d07a5375bc3cc1386f85ebaccf7 100644 (file)
@@ -63,6 +63,9 @@
 #include "pcode.h"
 #include "gen.h"
 
+
+#define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff)
+
 const char *AopType(short type)
 {
   switch(type) {
@@ -378,6 +381,7 @@ static void genAddLit (operand *result,operand *left, int lit)
 {
 
   int size,same;
+  int lo;
 
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
   size = pic14_getDataSize(result);
@@ -392,7 +396,7 @@ static void genAddLit (operand *result,operand *left, int lit)
      
     else if(size == 2) {
       int hi = 0xff & (lit >> 8);
-      int lo = lit & 0xff;
+      lo = lit & 0xff;
 
       switch(hi) {
       case 0: 
@@ -502,6 +506,102 @@ static void genAddLit (operand *result,operand *left, int lit)
        }
 
       }
+    } else {
+      int carry_info = 0;
+      int offset = 0;
+      /* size > 2 */
+      DEBUGpic14_emitcode (";  add lit to long","%s  %d",__FUNCTION__,__LINE__);
+
+      while(size--) {
+       lo = BYTEofLONG(lit,0);
+
+       if(carry_info) {
+         switch(lo) {
+         case 0:
+           switch(carry_info) {
+           case 1:
+             emitSKPNZ;
+             emitpcode(POC_INCF, popGet(AOP(result),offset,FALSE,FALSE));
+             break;
+           case 2:
+             emitpcode(POC_RLFW, popGet(AOP(result),offset,FALSE,FALSE));
+             emitpcode(POC_ANDLW,popGetLit(1));
+             emitpcode(POC_ADDWF, popGet(AOP(result),offset,FALSE,FALSE));
+             break;
+           default: /* carry_info = 3  */
+             emitSKPNC;
+             emitpcode(POC_INCF, popGet(AOP(result),offset,FALSE,FALSE));
+             carry_info = 1;
+             break;
+           }
+           break;
+         case 0xff:
+           emitpcode(POC_MOVLW,popGetLit(lo));
+           if(carry_info==1) 
+             emitSKPZ;
+           else
+             emitSKPC;
+           emitpcode(POC_ADDWF, popGet(AOP(result),offset,FALSE,FALSE));
+           break;
+         default:
+           emitpcode(POC_MOVLW,popGetLit(lo));
+           if(carry_info==1) 
+             emitSKPNZ;
+           else
+             emitSKPNC;
+           emitpcode(POC_MOVLW,popGetLit(lo+1));
+           emitpcode(POC_ADDWF, popGet(AOP(result),offset,FALSE,FALSE));
+           carry_info=2;
+           break;
+         }
+       }else {
+         /* no carry info from previous step */
+         /* this means this is the first time to add */
+         switch(lo) {
+         case 0:
+           break;
+         case 1:
+           emitpcode(POC_INCF, popGet(AOP(result),offset,FALSE,FALSE));
+           carry_info=1;
+           break;
+         default:
+           emitpcode(POC_MOVLW,popGetLit(lo));
+           emitpcode(POC_ADDWF, popGet(AOP(result),offset,FALSE,FALSE));
+           if(lit <0x100) 
+             carry_info = 3;  /* Were adding only one byte and propogating the carry */
+           else
+             carry_info = 2;
+           break;
+         }
+       }
+       offset++;
+       lit >>= 8;
+      }
+    
+/*
+      lo = BYTEofLONG(lit,0);
+
+      if(lit < 0x100) {
+       if(lo) {
+         if(lo == 1) {
+           emitpcode(POC_INCF, popGet(AOP(result),0,FALSE,FALSE));
+           emitSKPNZ;
+         } else {
+           emitpcode(POC_MOVLW,popGetLit(lo));
+           emitpcode(POC_ADDWF, popGet(AOP(result),0,FALSE,FALSE));
+           emitSKPNC;
+         }
+         emitpcode(POC_INCF, popGet(AOP(result),1,FALSE,FALSE));
+         emitSKPNZ;
+         emitpcode(POC_INCF, popGet(AOP(result),2,FALSE,FALSE));
+         emitSKPNZ;
+         emitpcode(POC_INCF, popGet(AOP(result),3,FALSE,FALSE));
+
+       } 
+      } 
+    }
+
+*/
     }
   } else {
     int offset = 1;
@@ -527,6 +627,8 @@ static void genAddLit (operand *result,operand *left, int lit)
        emitpcode(POC_ADDFW, popGet(AOP(left),0,FALSE,FALSE));
        emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
       }
+
+
     } else {
 
       if(lit & 0xff) {
index eb40eaa0b308d2b76ecbd0f7c8633e5c33abb70a..fd8001aabd4f7dfa188e324ac7c1435cb8d7f0a5 100644 (file)
@@ -64,6 +64,8 @@ SRC = b.c \
        compare2.c \
        compare3.c \
        compare4.c \
+       compare5.c \
+       compare6.c \
        for.c \
        rotate1.c \
        rotate2.c \
index c1d8fa7842ea001c7d69054f12e4225b6512dee3..3588708646ace9476ba9695e7cc50a3a2dfaefd4 100644 (file)
@@ -14,6 +14,12 @@ unsigned char dummy=0;
 char char0 = 0;
 char char1 = 0;
 char char2 = 0;
+int int0 = 0;
+int int1 = 0;
+long long0 = 0;
+long long1 = 0;
+unsigned long ulong0 = 0;
+unsigned long ulong1 = 0;
 
 #if SUPPORT_BIT_TYPES
 
@@ -62,6 +68,110 @@ void add_char2char(void)
 
 }
 
+void add_int2int(void)
+{
+  if(int0 != 4)
+    failures++;
+  if(int1 != 5)
+    failures++;
+
+  int0 += int1;
+  if(int0 != 9)
+    failures++;
+
+  int0 += 0x7fff;
+  if(int0 != -0x7ff8)
+    failures++;
+
+}
+
+void add_lit2long(void)
+{
+
+  if(long0 != 0)
+    failures++;
+
+  long0++;
+
+  if(long0 != 1)
+    failures++;
+
+  long0 = long0 + 0xff;
+
+  if(long0 != 0x100)
+    failures++;
+
+  long0 = long0 + 0x100;
+  if(long0 != 0x200)
+    failures++;
+
+
+  long0 = long0 + 0xfe00;
+  if(long0 != 0x10000)
+    failures++;
+
+  long0 = long0 + 0xff0000;
+  if(long0 != 0x1000000)
+    failures++;
+
+  long0 = long0 + 0x7e000000;
+  if(long0 != 0x7f000000)
+    failures++;
+
+  /* wrap around zero */
+  long0 = long0 + 0x2000000;
+  if(long0 != -0x7f000000)
+    failures++;
+
+  long0 = long0 + 0x7f000000;
+  if(long0 != 0)
+    failures++;
+
+}
+
+void add_lit2ulong(void)
+{
+
+  if(ulong0 != 0)
+    failures++;
+
+  ulong0++;
+
+  if(ulong0 != 1)
+    failures++;
+
+  ulong0 = ulong0 + 0xff;
+
+  if(ulong0 != 0x100)
+    failures++;
+
+  ulong0 = ulong0 + 0x100;
+  if(ulong0 != 0x200)
+    failures++;
+
+
+  ulong0 = ulong0 + 0xfe00;
+  if(ulong0 != 0x10000)
+    failures++;
+
+  ulong0 = ulong0 + 0xff0000;
+  if(ulong0 != 0x1000000)
+    failures++;
+
+  ulong0 = ulong0 + 0x7e000000;
+  if(ulong0 != 0x7f000000)
+    failures++;
+
+  ulong0 = ulong0 + 0x2000000;
+  if(ulong0 != 0x81000000)
+    failures++;
+
+  /* wrap around zero */
+  ulong0 = ulong0 + 0x7f000000;
+  if(ulong0)
+    failures++;
+
+}
 
 void main(void)
 {
@@ -69,6 +179,13 @@ void main(void)
   char1 = char0 + 1;
   add_char2char();
 
+  int0 = 4;
+  int1 = int0 + 1;
+  add_int2int();
+
+  add_lit2long();
+  add_lit2ulong();
+
   success = failures;
   done();
 }
index 6aa173e90edd7d9625a08d3f983551899bfe3473..6ff0cd5d3c14ad61a29a65f0d7fd65519566fa21 100644 (file)
@@ -197,8 +197,8 @@ void c_abcd(void)
   if(aint0 == 0x01cd)
     failures++;
 
-  if(aint0 == 0x1234abcd)
-    failures++;
+  //  if(aint0 == 0x1234abcd)
+    //    failures++;
 
 }
 
index 41e0b9c07241cbe7864b2ebb356280d2945da8bd..cf9265bcf3c0ccc7e59e9ce5e08bde9979196ea1 100644 (file)
@@ -3,7 +3,7 @@
 // regression testing program for comparing signed chars and ints
 //
 
-#define  COMPARE_OUT_OF_RANGE 1
+//#define  COMPARE_OUT_OF_RANGE 1
 
 unsigned char success = 0;
 unsigned char failures = 0;
@@ -178,6 +178,9 @@ void c_a500(void)
   if(int0 != 0xa500)
     failures++;
 
+  if(int0 != 0x44)
+    int0 = 0x28;
+
   if(int0 == 0xa400)
     failures++;
 
@@ -197,10 +200,10 @@ void c_abcd(void)
   if(char0 == 0xabcd)
     failures++;
 #endif
-
+/*
   if(int0 != 0xabcd)
     failures++;
-
+*/
   if(int0 == 0xab00)
     failures++;
 
diff --git a/src/regression/compare5.c b/src/regression/compare5.c
new file mode 100644 (file)
index 0000000..5c7e015
--- /dev/null
@@ -0,0 +1,406 @@
+//
+// compare5.c
+// regression testing program for comparing longs
+//
+
+#define  COMPARE_OUT_OF_RANGE 1
+
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
+
+bit bit0 = 0;
+int int0 = 0;
+int int1 = 0;
+char char0 = 0;
+char char1 = 0;
+long long0 = 0;
+long long1 = 0;
+unsigned long ulong0 = 0;
+unsigned long ulong1 = 0;
+
+void
+done ()
+{
+
+  dummy++;
+
+}
+
+// compare to 0
+// assumes
+// long0 == 0
+// ulong0 == 0
+
+void c_0(void)
+{
+
+  if(long0 != 0)
+    failures++;
+
+  if(long0 > 0)
+    failures++;
+
+  if(ulong0 != 0)
+    failures++;
+
+  if(ulong0 > 0)
+    failures++;
+
+  if(ulong0 < 0)
+    failures++;
+}
+
+// compare to 1
+// assumes
+// long1 == 1
+// ulong1 == 1
+
+void c_1(void)
+{
+
+  if(long0 == 1)
+    failures++;
+
+  if(long1 != 1)
+    failures++;
+
+  if(ulong0 == 1)
+    failures++;
+
+  if(ulong1 != 1)
+    failures++;
+
+  if(long1 < 0)
+    failures++;
+
+  if(ulong1 < 0)
+    failures++;
+
+  if(long1 < 1)
+    failures++;
+
+  if(ulong1 < 1)
+    failures++;
+
+  if(long1 > 1)
+    failures++;
+
+  if(ulong1 > 1)
+    failures++;
+}
+
+// compare to 2
+// assumes
+// long0 == 2
+// ulong0  == 2
+
+void c_2(void)
+{
+
+  if(long0 != 2)
+    failures++;
+
+  if(ulong0 != 2)
+    failures++;
+
+  if(long1 == 2)
+    failures++;
+
+  if(ulong1 == 2)
+    failures++;
+
+}
+
+// compare to 0xff
+// assumes
+// achar0 == 0xff
+// aint0  == 0xff
+
+void c_ff(void)
+{
+
+  if(long0 != 0xff)
+    failures++;
+
+  if(ulong0 != 0xff)
+    failures++;
+
+  if(long1 == 0xff)
+    failures++;
+
+  if(ulong1 == 0xff)
+    failures++;
+
+
+}
+
+// compare to 0x200
+// assumes
+// achar0 == 0x200
+// aint0  == 0x200
+
+void c_200(void)
+{
+
+  if(long0 != 0x200)
+    failures++;
+
+  if(ulong0 != 0x200)
+    failures++;
+
+  if(long1 == 0x200)
+    failures++;
+
+  if(ulong1 == 0x200)
+    failures++;
+
+
+}
+
+// compare to 0x20000
+// assumes
+// achar0 == 0x20000
+// aint0  == 0x20000
+
+void c_20000(void)
+{
+
+  if(long0 != 0x20000)
+    failures++;
+
+  if(ulong0 != 0x20000)
+    failures++;
+
+  if(long1 == 0x20000)
+    failures++;
+
+  if(ulong1 == 0x20000)
+    failures++;
+
+  if(long0 <= 0x10000)
+    failures++;
+
+  if(long0 < 0x10000)
+    failures++;
+
+  if(long0 < 0x12345)
+    failures++;
+
+  if(long0 == 0)
+    failures++;
+}
+
+// compare to 0x00a5
+// assumes
+// char0  == 0xa5
+// int0  == 0x00a5
+
+void c_a5(void)
+{
+
+  if(char0 != 0xa5)
+    failures++;
+
+  if(int0 != 0xa5)
+    failures++;
+
+  if(int0 == 0xa4)
+    failures++;
+
+  if(int0 == 0xa500)
+    failures++;
+
+}
+
+// compare to 0xa500
+// assumes
+// char0  == 0xa5
+// int0  == 0xa500
+
+void c_a500(void)
+{
+
+#ifdef COMPARE_OUT_OF_RANGE
+  if(char0 == 0xa500)
+    failures++;
+#endif
+
+  if(int0 != 0xa500)
+    failures++;
+
+  if(int0 == 0xa400)
+    failures++;
+
+  if(int0 == 0x00a5)
+    failures++;
+
+}
+
+// compare to 0xabcd
+// assumes
+// char0  == 0xa5
+// int0  == 0xabcd
+
+void c_abcd(void)
+{
+#ifdef COMPARE_OUT_OF_RANGE
+  if(char0 == 0xabcd)
+    failures++;
+#endif
+
+  if(int0 != 0xabcd)
+    failures++;
+
+  if(int0 == 0xab00)
+    failures++;
+
+  if(int0 == 0x00cd)
+    failures++;
+
+  if(int0 == 0x05cd)
+    failures++;
+
+  if(int0 == 0xab05)
+    failures++;
+
+  if(int0 == 0xab01)
+    failures++;
+
+  if(int0 == 0x01cd)
+    failures++;
+
+  if(int0 > 0)
+    failures++;
+
+#ifdef COMPARE_OUT_OF_RANGE
+  if(int0 == 0x1234abcd)
+    failures++;
+#endif
+
+}
+
+// assumes char1 == 0
+void c_ifelse1(void)
+{
+
+  if(char0)
+    char0 = char1;
+  else
+    char0 = 0;
+
+  if(char0)
+    failures++;
+}
+
+// assumes char0 = -1
+// assumes int0 = -1
+
+void c_minus1(void)
+{
+  if(long0 != -1)
+    failures++;
+
+  if(long0 > 0)
+    failures++;
+
+  if(long1 < 0)
+    failures++;
+
+  if(long1 < 2)
+    failures++;
+
+}
+
+// assumes
+// long0 = long1 = ulong0 = ulong1 == 0
+
+void c_long2long_eq(void)
+{
+
+  if(long0 != long1)
+    failures++;
+
+  if(ulong0 != ulong1)
+    failures++;
+
+  if(long0 != ulong1)
+    failures++;
+
+  if(long0 > long1)
+    failures++;
+
+  if(long0 < long1)
+    failures++;
+
+  if(long0 > ulong0)
+    failures++;
+
+  if(long0 < ulong0)
+    failures++;
+}
+
+// assumes
+// long0 = ulong0 == 0
+// long1 = ulong1 == 1
+
+void c_long2long_neq(void)
+{
+
+  if(long0 == long1)
+    failures++;
+
+  if(ulong0 == ulong1)
+    failures++;
+
+  if(long1 != ulong1)
+    failures++;
+
+  if(long1 < long0)
+    failures++;
+
+  if(long1 <= long0)
+    failures++;
+
+  if(ulong1 < ulong0)
+    failures++;
+
+  if(ulong1 <= ulong0)
+    failures++;
+
+}
+void
+main (void)
+{
+
+  c_0();
+
+  c_long2long_eq();
+
+  long1 = 1;
+  ulong1 = 1;
+  c_1();
+  c_long2long_neq();
+
+  long0 = 2;
+  ulong0 = 2;
+  c_2();
+
+  long0 = 0xff;
+  ulong0 = 0xff;
+  c_ff();
+
+  long0 = 0x200;
+  ulong0 = 0x200;
+  c_200();
+
+  long0 = 0x20000;
+  ulong0 = 0x20000;
+  c_20000();
+
+  long0 = -1;
+  c_minus1();
+
+  success = failures;
+  done ();
+}