Yet again, signed comparisons to literals has been fixed.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 18 Dec 2001 17:01:47 +0000 (17:01 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 18 Dec 2001 17:01:47 +0000 (17:01 +0000)
  * compare9.c - an exhaustive '<=' compare to char and int literals
  * compare10.c - an exhaustive '>=' compare to char and int literals

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

src/pic/gen.c
src/pic/pcode.c
src/pic/pcodepeep.c
src/pic/peeph.def
src/regression/compare10.c [new file with mode: 0644]
src/regression/compare7.c
src/regression/compare8.c
src/regression/compare9.c [new file with mode: 0644]

index 3fffd135bc0d52732305710c99fa3aa2b99c5101..78091f79b5e381d1daeef0093699378c91a1c2a5 100644 (file)
@@ -3519,16 +3519,20 @@ static void genCmp (operand *left,operand *right,
 {
   int size, offset = 0 ;
   unsigned long lit = 0L,i = 0;
-  resolvedIfx rIfx;
-
+  resolvedIfx rFalseIfx;
+  //  resolvedIfx rTrueIfx;
+  symbol *truelbl;
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
   if(ifx) {
   DEBUGpic14_emitcode ("; ***","true ifx is %s",((IC_TRUE(ifx) == NULL) ? "false" : "true"));
   DEBUGpic14_emitcode ("; ***","false ifx is %s",((IC_FALSE(ifx) == NULL) ? "false" : "true"));
   }
 
-  resolveIfx(&rIfx,ifx);
 
+  resolveIfx(&rFalseIfx,ifx);
+  truelbl  = newiTempLabel(NULL);
+
+  //if(IC_TRUE(ifx) == NULL)
   /* if left & right are bit variables */
   if (AOP_TYPE(left) == AOP_CRY &&
       AOP_TYPE(right) == AOP_CRY ) {
@@ -3552,9 +3556,6 @@ static void genCmp (operand *left,operand *right,
     } else {
 
       symbol *lbl  = newiTempLabel(NULL);
-      int emitFinalCheck=1;
-      symbol *truelbl  = newiTempLabel(NULL);
-
 
       if(AOP_TYPE(right) == AOP_LIT) {
 
@@ -3567,12 +3568,12 @@ static void genCmp (operand *left,operand *right,
        if(lit == 0) {
 
          if(sign != 0) 
-           genSkipCond(&rIfx,left,size-1,7);
+           genSkipCond(&rFalseIfx,left,size-1,7);
          else 
            /* no need to compare to 0...*/
            /* NOTE: this is a de-generate compare that most certainly 
             *       creates some dead code. */
-           emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+           emitpcode(POC_GOTO,popGetLabel(rFalseIfx.lbl->key));
 
          if(ifx) ifx->generated = 1;
          return;
@@ -3592,16 +3593,16 @@ static void genCmp (operand *left,operand *right,
              /* lit is 0x7f, all signed chars are less than
               * this except for 0x7f itself */
              emitpcode(POC_XORLW, popGetLit(0x7f));
-             genSkipz2(&rIfx);
+             genSkipz2(&rFalseIfx);
            } else {
              emitpcode(POC_ADDLW, popGetLit(0x80));
              emitpcode(POC_ADDLW, popGetLit(i^0x80));
-             genSkipc(&rIfx);
+             genSkipc(&rFalseIfx);
            }
 
          } else {
            emitpcode(POC_ADDLW, popGetLit(i));
-           genSkipc(&rIfx);
+           genSkipc(&rFalseIfx);
 
          }
 
@@ -3619,7 +3620,7 @@ static void genCmp (operand *left,operand *right,
        if(sign) {
 
          if(lit == 0) {
-           genSkipCond(&rIfx,left,size,7);
+           genSkipCond(&rFalseIfx,left,size,7);
            if(ifx) ifx->generated = 1;
            return;
          }
@@ -3627,8 +3628,16 @@ static void genCmp (operand *left,operand *right,
          if(lit <0x100) {
            DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
 
+           //rFalseIfx.condition ^= 1;
+           //genSkipCond(&rFalseIfx,left,size,7);
+           //rFalseIfx.condition ^= 1;
+
            emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
-           emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+           if(rFalseIfx.condition)
+             emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
+           else
+             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+
            emitpcode(POC_MOVLW, popGetLit(0x100-lit));
            emitpcode(POC_ADDFW, popGet(AOP(left),0));
            emitpcode(POC_MOVFW, popGet(AOP(left),1));
@@ -3636,9 +3645,15 @@ static void genCmp (operand *left,operand *right,
            while(size > 1)
              emitpcode(POC_IORFW, popGet(AOP(left),size--));
 
-           emitSKPNZ;
+           if(rFalseIfx.condition) {
+             emitSKPZ;
+             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
 
-           genSkipc(&rIfx);
+           } else {
+             emitSKPNZ;
+           }
+
+           genSkipc(&rFalseIfx);
            emitpLabel(truelbl->key);
            if(ifx) ifx->generated = 1;
            return;
@@ -3654,7 +3669,7 @@ static void genCmp (operand *left,operand *right,
              emitpcode(POC_MOVFW, popGet(AOP(left),size));
              emitpcode(POC_ADDLW, popGetLit( 0x80));
              emitpcode(POC_ADDLW, popGetLit(0x100-i));
-             genSkipc(&rIfx);
+             genSkipc(&rFalseIfx);
 
 
              if(ifx) ifx->generated = 1;
@@ -3670,40 +3685,13 @@ static void genCmp (operand *left,operand *right,
              emitpcode(POC_MOVFW, popGet(AOP(left),size));
              emitpcode(POC_ADDLW, popGetLit( 0x80));
              emitpcode(POC_ADDLW, popGetLit(0x100-i));
-             genSkipc(&rIfx);
-
-
-             if(ifx) ifx->generated = 1;
-             return;
-
-           }
-
-#if 0
-           if( lit < 0x10000) {
-             /* upper word is zero */
-             DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
-
-             emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
-             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
-
-             emitpcode(POC_MOVLW, popGetLit((lit >> (1*8)) & 0xff));
-             emitpcode(POC_SUBFW, popGet(AOP(left),1));
-             emitpcode(POC_MOVLW, popGetLit((lit & 0xff));
-             emitSKPNZ;
-             emitpcode(POC_SUBFW, popGet(AOP(left),0));
-
-             emitpcode(POC_IORFW, popGet(AOP(left),2));
-             emitpcode(POC_IORFW, popGet(AOP(left),3));
+             genSkipc(&rFalseIfx);
 
-             emitSKPNZ;
 
-             genSkipc(&rIfx);
-             emitpLabel(truelbl->key);
              if(ifx) ifx->generated = 1;
              return;
 
            }
-#endif
 
          }
 
@@ -3712,13 +3700,30 @@ static void genCmp (operand *left,operand *right,
            /* lit is negative */
            DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
 
-           genSkipCond(&rIfx,left,size,7);
+           //genSkipCond(&rFalseIfx,left,size,7);
+
+           emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+
+           if(rFalseIfx.condition)
+             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+           else
+             emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
+
+
          } else {
            /* lit is positive */
            DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
            emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
-           emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+           if(rFalseIfx.condition)
+             emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
+           else
+             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
 
+           //emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+           //emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+           //rFalseIfx.condition ^= 1;
+           //genSkipCond(&rFalseIfx,left,size,7);
+           //rFalseIfx.condition ^= 1;
          }
 
          /*
@@ -3729,7 +3734,7 @@ static void genCmp (operand *left,operand *right,
            emitpcode(POC_RLFW,  popCopyReg(&pc_kzero));
            emitpcode(POC_ADDLW, popGetLit( ((mlit>>8) & 0xff)));
            emitpcode(POC_ADDFW, popGet(AOP(left),1));
-           genSkipc(&rIfx);
+           genSkipc(&rFalseIfx);
 
            emitpLabel(truelbl->key);
            if(ifx) ifx->generated = 1;
@@ -3747,8 +3752,8 @@ static void genCmp (operand *left,operand *right,
            emitSKPNZ;
            emitpcode(POC_SUBFW, popGet(AOP(left),size));
          }
-
-         genSkipc(&rIfx);
+         //rFalseIfx.condition ^= 1;
+         genSkipc(&rFalseIfx);
 
          emitpLabel(truelbl->key);
 
@@ -3787,8 +3792,8 @@ static void genCmp (operand *left,operand *right,
 
 
        emitpLabel(lbl->key);
-       if(emitFinalCheck)
-         genSkipc(&rIfx);
+       //if(emitFinalCheck)
+         genSkipc(&rFalseIfx);
        if(sign)
          emitpLabel(truelbl->key);
 
@@ -3800,9 +3805,9 @@ static void genCmp (operand *left,operand *right,
 
       if(AOP_TYPE(left) == AOP_LIT) {
        //symbol *lbl = newiTempLabel(NULL);
-       unsigned long mlit;
+
        lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit));
-       mlit = -lit;
+
 
        DEBUGpic14_emitcode(";left lit","lit = %d,sign=%d",lit,sign);
 
@@ -3814,8 +3819,8 @@ static void genCmp (operand *left,operand *right,
          while(size) 
            emitpcode(POC_IORFW, popGet(AOP(right),--size));
 
-         //rIfx.condition ^= 1;
-         genSkipz2(&rIfx);
+         //rFalseIfx.condition ^= 1;
+         genSkipz2(&rFalseIfx);
          if(ifx) ifx->generated = 1;
          return;
        }
@@ -3825,7 +3830,9 @@ static void genCmp (operand *left,operand *right,
          lit &= 0xff;
          if(((lit == 0xff) && !sign) || ((lit==0x7f) && sign)) {
            /* degenerate compare can never be true */
-           emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+           if(rFalseIfx.condition == 0)
+             emitpcode(POC_GOTO,popGetLabel(rFalseIfx.lbl->key));
+
            if(ifx) ifx->generated = 1;
            return;
          }
@@ -3835,11 +3842,11 @@ static void genCmp (operand *left,operand *right,
              emitpcode(POC_MOVFW, popGet(AOP(right),0));
              emitpcode(POC_ADDLW, popGetLit(0x80));
              emitpcode(POC_ADDLW, popGetLit(((-(lit+1)) & 0xff) ^ 0x80));
-             rIfx.condition ^= 1;
-             genSkipc(&rIfx);
+             rFalseIfx.condition ^= 1;
+             genSkipc(&rFalseIfx);
            } else {
-             rIfx.condition ^= 1;
-             genSkipCond(&rIfx,right,0,7);
+             rFalseIfx.condition ^= 1;
+             genSkipCond(&rFalseIfx,right,0,7);
            }
            
          } else {
@@ -3847,11 +3854,11 @@ static void genCmp (operand *left,operand *right,
              emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
              emitpcode(POC_SUBFW, popGet(AOP(right),0));
              DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-             rIfx.condition ^= 1;
-             genSkipc(&rIfx);
+             rFalseIfx.condition ^= 1;
+             genSkipc(&rFalseIfx);
            } else { 
              emitpcode(POC_MOVFW, popGet(AOP(right),0));
-             genSkipz2(&rIfx);
+             genSkipz2(&rFalseIfx);
            }
          }
 
@@ -3874,21 +3881,34 @@ static void genCmp (operand *left,operand *right,
 
 
              DEBUGpic14_emitcode(";left lit = -1","line = %d ",__LINE__);
-             rIfx.condition ^= 1;
-             genSkipCond(&rIfx,right,size,7);
+             rFalseIfx.condition ^= 1;
+             genSkipCond(&rFalseIfx,right,size,7);
              if(ifx) ifx->generated = 1;
              return;
            }
 
            if(lit == 0) {
              int s = size;
+
+             if(rFalseIfx.condition) {
+               emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+               emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+             }
+
              emitpcode(POC_MOVFW, popGet(AOP(right),size));
              while(size--)
                emitpcode(POC_IORFW, popGet(AOP(right),size));
 
+
              emitSKPZ;
-             rIfx.condition ^= 1;
-             genSkipCond(&rIfx,right,s,7);
+             if(rFalseIfx.condition) {
+               emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
+               emitpLabel(truelbl->key);
+             }else {
+               rFalseIfx.condition ^= 1;
+               genSkipCond(&rFalseIfx,right,s,7);
+             }
+
              if(ifx) ifx->generated = 1;
              return;
            }
@@ -3897,15 +3917,33 @@ static void genCmp (operand *left,operand *right,
            if(lit & (0x80 << (size*8))) {
              /* Lit is less than zero */
              DEBUGpic14_emitcode(";left lit","line = %d  0x%x is less than 0",__LINE__,lit);
+             //rFalseIfx.condition ^= 1;
+             //genSkipCond(&rFalseIfx,left,size,7);
+             //rFalseIfx.condition ^= 1;
              emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
-             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+             //emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+
+             if(rFalseIfx.condition)
+               emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
+             else
+               emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+
 
            } else {
              /* Lit is greater than or equal to zero */
              DEBUGpic14_emitcode(";left lit","line = %d  0x%x is greater than 0",__LINE__,lit);
-             rIfx.condition ^= 1;
-             genSkipCond(&rIfx,right,size,7);
-             rIfx.condition ^= 1;
+             //rFalseIfx.condition ^= 1;
+             //genSkipCond(&rFalseIfx,right,size,7);
+             //rFalseIfx.condition ^= 1;
+
+             //emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+             //emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
+
+             emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+             if(rFalseIfx.condition)
+               emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+             else
+               emitpcode(POC_GOTO,  popGetLabel(rFalseIfx.lbl->key));
 
            }
            emitpcode(POC_MOVLW, popGetLit((lp1 >> (size*8)) & 0xff));
@@ -3917,8 +3955,9 @@ static void genCmp (operand *left,operand *right,
              emitSKPNZ;
              emitpcode(POC_SUBFW, popGet(AOP(right),size));
            }
-           rIfx.condition ^= 1;
-           genSkipc(&rIfx);
+           rFalseIfx.condition ^= 1;
+           //rFalseIfx.condition = 1;
+           genSkipc(&rFalseIfx);
 
            emitpLabel(truelbl->key);
 
@@ -3950,8 +3989,8 @@ static void genCmp (operand *left,operand *right,
 
            emitpLabel(lbl->key);
 
-           rIfx.condition ^= 1;
-           genSkipc(&rIfx);
+           rFalseIfx.condition ^= 1;
+           genSkipc(&rFalseIfx);
 
          }
        if(sign)
@@ -3985,7 +4024,7 @@ static void genCmp (operand *left,operand *right,
          emitpcode(POC_ADDLW, popGetLit(0x80));
 
          DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-         genSkipc(&rIfx);
+         genSkipc(&rFalseIfx);
          
          if(ifx) ifx->generated = 1;
          return;
@@ -4014,7 +4053,7 @@ static void genCmp (operand *left,operand *right,
       emitpLabel(lbl->key);
 
       DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-      genSkipc(&rIfx);
+      genSkipc(&rFalseIfx);
       if(ifx) ifx->generated = 1;
       return;
 
index 884ff12e515430e569c706e97f28c3ed6be51ee4..0f9357529c214e6755c551ed509e93f0aac62b5a 100644 (file)
@@ -2103,9 +2103,10 @@ void AnalyzepBlock(pBlock *pb)
          memcpy(r,PCOR(PCI(pc)->pcop)->r, sizeof(regs));
          addSet(&pb->registers, r);
          PCOR(PCI(pc)->pcop)->r = r;
-         fprintf(stderr,"added register to pblock: reg %d\n",r->rIdx);
-       } else 
+         //fprintf(stderr,"added register to pblock: reg %d\n",r->rIdx);
+       }/* else 
          fprintf(stderr,"found register in pblock: reg %d\n",r->rIdx);
+        */
       }
       if(PCI(pc)->pcop->type == PO_GPR_REGISTER) {
        if(PCOR(PCI(pc)->pcop)->r) {
@@ -2137,7 +2138,8 @@ int OptimizepBlock(pBlock *pb)
   fprintf(stderr," Optimizing pBlock: %c\n",getpBlock_dbName(pb));
   for(pc = pb->pcHead; pc; pc = pc->next)
     matches += pCodePeepMatchRule(pc);
-
+  if(matches)
+    fprintf(stderr," Optimizing pBlock: %c - matches=%d\n",getpBlock_dbName(pb),matches);
   return matches;
 
 }
@@ -2229,14 +2231,14 @@ void pBlockMergeLabels(pBlock *pb)
   for(pc = pb->pcHead; pc; pc = pc->next) {
 
     if(pc->type == PC_LABEL) {
-      fprintf(stderr,"Checking label key = %d\n",PCL(pc)->key);
+      //fprintf(stderr,"Checking label key = %d\n",PCL(pc)->key);
       if( !(pcnext = findNextInstruction(pc)) ) 
        return;  // Couldn't find an instruction associated with this label
 
       // Unlink the pCode label from it's pCode chain
       unlinkPC(pc);
 
-      fprintf(stderr,"Merged label key = %d\n",PCL(pc)->key);
+      //fprintf(stderr,"Merged label key = %d\n",PCL(pc)->key);
       // And link it into the instruction's pBranch labels. (Note, since
       // it's possible to have multiple labels associated with one instruction
       // we must provide a means to accomodate the additional labels. Thus
@@ -2303,11 +2305,12 @@ void AnalyzepCode(char dbName)
   if(!the_pFile)
     return;
 
-  fprintf(stderr," Analyzing pCode");
 
-  changes = 0;
   i = 0;
   do {
+
+    fprintf(stderr," Analyzing pCode: PASS #%d\n",i+1);
+
     /* First, merge the labels with the instructions */
     for(pb = the_pFile->pbHead; pb; pb = pb->next) {
       if('*' == dbName || getpBlock_dbName(pb) == dbName) {
@@ -2318,6 +2321,8 @@ void AnalyzepCode(char dbName)
       }
     }
 
+    changes = 0;
+
     for(pb = the_pFile->pbHead; pb; pb = pb->next) {
       if('*' == dbName || getpBlock_dbName(pb) == dbName)
        changes += OptimizepBlock(pb);
index 0465edb61f76b27e01ee03f2b58e2a57da1bd3ec..115852a54fc6ee11222c496789e130829b85abdc 100644 (file)
@@ -996,8 +996,8 @@ void parseTokens(void)
 
        if( altArr[k].f) {
          pc = altArr[k].f(&parsedPatArr[j]);
-         if(pc && pc->print)
-           pc->print(stderr,pc);
+         //if(pc && pc->print)
+         //  pc->print(stderr,pc);
          //if(pc && pc->destruct) pc->destruct(pc); dumps core?
          if(curBlock && pc)
            addpCode2pBlock(curBlock, pc);
@@ -1038,7 +1038,7 @@ void  peepRuleBlock2pCodeBlock(  lineNode *ln)
 
   for( ; ln; ln = ln->next) {
 
-    fprintf(stderr,"%s\n",ln->line);
+    //fprintf(stderr,"%s\n",ln->line);
 
     tokenizeLineNode(ln->line);
     parseTokens();
@@ -1054,12 +1054,12 @@ static void   peepRuleCondition(char *cond)
   if(!cond)
     return;
 
-  fprintf(stderr,"\nCondition:  %s\n",cond);
+  //fprintf(stderr,"\nCondition:  %s\n",cond);
 
   /* brute force compares for now */
 
   if(STRCASECMP(cond, "NZ") == 0) {
-    fprintf(stderr,"found NZ\n");
+    //fprintf(stderr,"found NZ\n");
     curPeep->postFalseCond = PCC_Z;
 
   }
@@ -1093,7 +1093,7 @@ void  peepRules2pCode(peepRule *rules)
 
   for (pr = rules; pr; pr = pr->next) {
 
-    fprintf(stderr,"\nRule:\n\n");
+    //fprintf(stderr,"\nRule:\n\n");
 
     pcps = Safe_calloc(1,sizeof(pCodePeepSnippets));
     curPeep = pcps->peep  = Safe_calloc(1,sizeof(pCodePeep));
@@ -1112,14 +1112,14 @@ void  peepRules2pCode(peepRule *rules)
     /* Convert the target block */
     peepRuleBlock2pCodeBlock(pr->match);
 
-    fprintf(stderr,"finished target, here it is in pcode form:\n");
-    printpBlock(stderr, curBlock);
+    //fprintf(stderr,"finished target, here it is in pcode form:\n");
+    //printpBlock(stderr, curBlock);
 
-    fprintf(stderr,"target with labels merged:\n");
+    //fprintf(stderr,"target with labels merged:\n");
     pBlockMergeLabels(curBlock);
     printpBlock(stderr, curBlock);
 
-    fprintf(stderr,"\nReplaced by:\n");
+    //fprintf(stderr,"\nReplaced by:\n");
 
 
     curPeep->replace = curBlock = newpCodeChain(NULL, 'W', NULL);
@@ -1127,12 +1127,12 @@ void  peepRules2pCode(peepRule *rules)
     /* Convert the replace block */
     peepRuleBlock2pCodeBlock(pr->replace);
 
-    fprintf(stderr,"finished replace block, here it is in pcode form:\n");
-    printpBlock(stderr, curBlock);
+    //fprintf(stderr,"finished replace block, here it is in pcode form:\n");
+    //printpBlock(stderr, curBlock);
 
-    fprintf(stderr,"replace with labels merged:\n");
+    //fprintf(stderr,"replace with labels merged:\n");
     pBlockMergeLabels(curBlock);
-    printpBlock(stderr, curBlock);
+    //printpBlock(stderr, curBlock);
 
     peepRuleCondition(pr->cond);
 
@@ -1267,22 +1267,22 @@ int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
       return 0;
 
     pcl = pcd->label->pc;
-    //labindex = PCOW(pcl)->id;
+
     labindex = -PCL(pcl)->key;
-    fprintf(stderr,"label id = %d (labindex = %d)\n",PCL(pcl)->key,labindex);
+    //fprintf(stderr,"label id = %d (labindex = %d)\n",PCL(pcl)->key,labindex);
     if(peepBlock->vars[labindex] == NULL) {
       // First time to encounter this label
       peepBlock->vars[labindex] = PCL(pcs->label->pc)->label;
-      fprintf(stderr,"first time for a label: %d %s\n",labindex, peepBlock->vars[labindex]);
+      //fprintf(stderr,"first time for a label: %d %s\n",labindex, peepBlock->vars[labindex]);
     } else {
       if(strcmp(peepBlock->vars[labindex],PCL(pcs->label->pc)->label) != 0) {
-       fprintf(stderr,"labels don't match\n");
+       // fprintf(stderr,"labels don't match\n");
        return 0;
       }
-      fprintf(stderr,"matched a label\n");
+      //fprintf(stderr,"matched a label\n");
     }
   } else {
-    fprintf(stderr,"destination doesn't have a label\n");
+    // fprintf(stderr,"destination doesn't have a label\n");
 
     if(pcs->label)
       return 0;
@@ -1331,9 +1331,11 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
       if(PCI(pcs)->op != PCI(pcd)->op)
        return 0;
 
+      /*
       fprintf(stderr,"%s comparing\n",__FUNCTION__);
       pcs->print(stderr,pcs);
       pcd->print(stderr,pcd);
+      */
 
       if(!pCodePeepMatchLabels(peepBlock, pcs, pcd))
        return 0;
@@ -1343,7 +1345,7 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
        if (PCI(pcd)->pcop->type == PO_WILD) {
          index = PCOW(PCI(pcd)->pcop)->id;
 
-         fprintf(stderr,"destination is wild\n");
+         //fprintf(stderr,"destination is wild\n");
 #ifdef DEBUG_PCODEPEEP
          if (index > peepBlock->nops) {
            fprintf(stderr,"%s - variables exceeded\n",__FUNCTION__);
@@ -1360,7 +1362,6 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
          {
            char *n;
 
-             fprintf(stderr,"line %d\n",__LINE__);
            switch(PCI(pcs)->pcop->type) {
            case PO_GPR_TEMP:
            case PO_FSR:
@@ -1369,15 +1370,14 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
              break;
            default:
-             fprintf(stderr,"line %d\n",__LINE__);
              n = PCI(pcs)->pcop->name;
            }
 
            if(peepBlock->vars[index])
              return  (strcmp(peepBlock->vars[index],n) == 0);
            else {
-             fprintf(stderr,"first time for a variable: %d, %s\n",index,n);
-             peepBlock->vars[index] = n; //PCI(pcs)->pcop->name;
+             // fprintf(stderr,"first time for a variable: %d, %s\n",index,n);
+             peepBlock->vars[index] = n;
              return 1;
            }
          }
@@ -1396,9 +1396,9 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
     index = PCW(pcd)->id;
 
-    fprintf(stderr,"%s comparing wild cards\n",__FUNCTION__);
-    pcs->print(stderr,pcs);
-    pcd->print(stderr,pcd);
+    //    fprintf(stderr,"%s comparing wild cards\n",__FUNCTION__);
+    //pcs->print(stderr,pcs);
+    //pcd->print(stderr,pcd);
 
     peepBlock->wildpCodes[PCW(pcd)->id] = pcs;
 
@@ -1409,6 +1409,7 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
       PCOW(PCI(pcd)->pcop)->matched = PCI(pcs)->pcop;
       if(peepBlock->vars[index]) {
        int i = (strcmp(peepBlock->vars[index],PCI(pcs)->pcop->name) == 0);
+       /*
        if(i)
          fprintf(stderr," (matched)\n");
        else {
@@ -1417,6 +1418,7 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
                  peepBlock->vars[index],
                  PCI(pcs)->pcop->name);
        }
+       */
        return i;
       } else {
        peepBlock->vars[index] = PCI(pcs)->pcop->name;
@@ -1426,8 +1428,8 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
     pcs = findNextInstruction(pcs->next); 
     if(pcs) {
-      fprintf(stderr," (next to match)\n");
-      pcs->print(stderr,pcs);
+      //fprintf(stderr," (next to match)\n");
+      //pcs->print(stderr,pcs);
     } else if(pcd->next) {
       /* oops, we ran out of code, but there's more to the rule */
       return 0;
@@ -1487,7 +1489,7 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
   switch(pcop->type) { 
   case PO_CRY:
   case PO_BIT:
-    fprintf(stderr,"pCodeOpCopy bit\n");
+    //fprintf(stderr,"pCodeOpCopy bit\n");
     pcopnew = Safe_calloc(1,sizeof(pCodeOpBit) );
     PCOB(pcopnew)->bit = PCOB(pcop)->bit;
     PCOB(pcopnew)->inBitSpace = PCOB(pcop)->inBitSpace;
@@ -1497,28 +1499,28 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
   case PO_WILD:
     /* Here we expand the wild card into the appropriate type: */
     /* By recursively calling pCodeOpCopy */
-    fprintf(stderr,"pCodeOpCopy wild\n");
+    //fprintf(stderr,"pCodeOpCopy wild\n");
     if(PCOW(pcop)->matched)
       pcopnew = pCodeOpCopy(PCOW(pcop)->matched);
     else {
       // Probably a label
       pcopnew = pCodeOpCopy(PCOW(pcop)->subtype);
       pcopnew->name = Safe_strdup(PCOW(pcop)->pcp->vars[PCOW(pcop)->id]);
-      fprintf(stderr,"copied a wild op named %s\n",pcopnew->name);
+      //fprintf(stderr,"copied a wild op named %s\n",pcopnew->name);
     }
 
     return pcopnew;
     break;
 
   case PO_LABEL:
-    fprintf(stderr,"pCodeOpCopy label\n");
+    //fprintf(stderr,"pCodeOpCopy label\n");
     pcopnew = Safe_calloc(1,sizeof(pCodeOpLabel) );
     PCOLAB(pcopnew)->key =  PCOLAB(pcop)->key;
     break;
 
   case PO_LITERAL:
   case PO_IMMEDIATE:
-    fprintf(stderr,"pCodeOpCopy lit\n");
+    //fprintf(stderr,"pCodeOpCopy lit\n");
     pcopnew = Safe_calloc(1,sizeof(pCodeOpLit) );
     PCOL(pcopnew)->lit = PCOL(pcop)->lit;
     break;
@@ -1528,7 +1530,7 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
   case PO_GPR_BIT:
   case PO_FSR:
   case PO_INDF:
-    fprintf(stderr,"pCodeOpCopy GPR register\n");
+    //fprintf(stderr,"pCodeOpCopy GPR register\n");
     pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
     PCOR(pcopnew)->r = PCOR(pcop)->r;
     PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
@@ -1536,7 +1538,7 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
     break;
 
   case PO_DIR:
-    fprintf(stderr,"pCodeOpCopy PO_DIR\n");
+    //fprintf(stderr,"pCodeOpCopy PO_DIR\n");
   case PO_SFR_REGISTER:
   case PO_STR:
   case PO_NONE:
@@ -1545,7 +1547,7 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
   case PO_PCL:
   case PO_PCLATH:
 
-    fprintf(stderr,"pCodeOpCopy register type %d\n", pcop->type);
+    //fprintf(stderr,"pCodeOpCopy register type %d\n", pcop->type);
     pcopnew = Safe_calloc(1,sizeof(pCodeOp) );
 
   }
@@ -1618,7 +1620,7 @@ int pCodePeepMatchRule(pCode *pc)
       pcin = findNextInstruction(pcin->next);
       pct = pct->next;
       //debug:
-      fprintf(stderr,"    matched\n");
+      //fprintf(stderr,"    matched\n");
       if(!pcin)
        fprintf(stderr," end of code\n");
       if(!pct)
@@ -1698,7 +1700,7 @@ int pCodePeepMatchRule(pCode *pc)
             * Is it wild? */
            if(PCI(pcr)->pcop->type == PO_WILD) {
              int index = PCOW(PCI(pcr)->pcop)->id;
-             fprintf(stderr,"copying wildopcode\n");
+             //fprintf(stderr,"copying wildopcode\n");
              if(peepBlock->wildpCodeOps[index])
                pcop = pCodeOpCopy(peepBlock->wildpCodeOps[index]);
              else
@@ -1706,7 +1708,7 @@ int pCodePeepMatchRule(pCode *pc)
            } else
              pcop = pCodeOpCopy(PCI(pcr)->pcop);
          }
-         fprintf(stderr,"inserting pCode\n");
+         //fprintf(stderr,"inserting pCode\n");
          pCodeInsertAfter(pc, newpCode(PCI(pcr)->op,pcop));
        } else if (pcr->type == PC_WILD) {
          pCodeInsertAfter(pc,peepBlock->wildpCodes[PCW(pcr)->id]);
@@ -1716,8 +1718,8 @@ int pCodePeepMatchRule(pCode *pc)
 
 
        pc = pc->next;
-       if(pc)
-         pc->print(stderr,pc);
+       //if(pc)
+       //  pc->print(stderr,pc);
        pcr = pcr->next;
       }
 
@@ -1729,84 +1731,3 @@ int pCodePeepMatchRule(pCode *pc)
 
   return 0;
 }
-
-
-
-
-
-
-
-
-
-
-#if 0
-/*******************/
-pCode *parseLineNode(char *ln)
-{
-  char buffer[50], *s;
-  int state=0;          //0 label, 1 mnemonic, 2 operand, 3 operand, 4 comment
-  int var;
-  pCode *pc = NULL;
-  //  pCodeLabel *pcl = NULL;
-
-  if(!ln || !*ln)
-    return pc;
-
-  s = buffer;
-  *s = 0;
-
-  while(*ln) {
-
-    /* skip white space */
-    while (isspace (*ln))
-      ln++;
-
-    switch(state) {
-
-    case 0:   // look for a label
-    case 1:   // look for mnemonic
-
-      if(*ln == '%') {
-
-       // Wild
-
-       ln++;
-       if(!isdigit(*ln) )
-         break;
-         //goto next_state;
-
-       var = strtol(ln, &ln, 10);
-       if(*ln  == ':') {
-         // valid wild card label
-         fprintf(stderr, " wildcard label: %d\n",var);
-         ln++;
-       } else
-         fprintf(stderr, " wild opcode: %d\n",var), state++;
-
-      } else {
-       // not wild
-       // Extract the label/mnemonic from the line
-
-       s = buffer;
-       while(*ln && !(isspace(*ln) || *ln == ':'))
-         *s++ = *ln++;
-
-       *s = 0;
-       if(*ln == ':')
-         fprintf(stderr," regular label: %s\n",buffer), ln++;
-       else
-         fprintf(stderr," regular mnem: %s\n",buffer), state++;
-      }
-      state++;
-      break;
-
-    default:
-      ln++;
-
-    }
-  }
-
-  return pc;
-  
-}
-#endif
index 6cbd71ad4e4d70378bdd92a3d4eed777185995f7..d6a80a0e98c17d71c130ef1b786c23edbe24353e 100644 (file)
@@ -94,6 +94,30 @@ replace restart {
 %2:    %4
 }
 
+replace restart {
+        btfss  %1
+        goto   %4
+%2:    %3
+%4:    %5
+} by {
+       ;peep 1b - test/jump to test/skip
+       btfsc   %1
+%2:    %3
+%4:    %5
+}
+
+replace restart {
+        btfsc  %1
+        goto   %4
+%2:    %3
+%4:    %5
+} by {
+       ;peep 1c - test/jump to test/skip
+       btfss   %1
+%2:    %3
+%4:    %5
+}
+
 
 //bogus test for pcode
 //replace restart {
diff --git a/src/regression/compare10.c b/src/regression/compare10.c
new file mode 100644 (file)
index 0000000..f8f045c
--- /dev/null
@@ -0,0 +1,309 @@
+// Signed comparisons of the form:  (variable>=LIT)
+//
+// This regression test exercises all of the boundary
+// conditions in literal less than comparisons. There
+// are numerous opportunities to optimize these comparison
+// and each one has an astonishing capability of failing
+// a boundary condition.
+
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
+unsigned char result = 0;
+
+//bit bit0 = 0;
+int int0 = 0;
+int int1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+signed char char0 = 0;
+signed char char1 = 0;
+char long0 = 0;
+char long1 = 0;
+
+void
+done ()
+{
+  dummy++;
+}
+
+
+void c_char_gte_lit1(unsigned char expected_result)
+{
+  result = 0;
+
+  if(char0 >= -0x7f)
+    result |= 1;
+
+
+  if(char0 >= -1)
+    result |= 2;
+
+  if(char0 >= 0)
+    result |= 4;
+
+  if(char0 >= 1)
+    result |= 8;
+
+  if(char0 >= 0x7e)
+    result |= 0x10;
+  
+  if(char0 >= 0x7f)
+    result |= 0x20;
+  
+  if(result != expected_result)
+    failures++;
+}
+
+
+void char_compare(void)
+{
+  char0 = 0x7f;
+  c_char_gte_lit1(0x3f);
+
+  char0 = 0x7e;
+  c_char_gte_lit1(0x1f);
+
+  char0 = 0x40;
+  c_char_gte_lit1(0x0f);
+
+  char0 = 0x2;
+  c_char_gte_lit1(0x0f);
+
+  char0 = 0x1;
+  c_char_gte_lit1(0x0f);
+
+  char0 = 0;
+  c_char_gte_lit1(0x07);
+
+  char0 = -1;
+  c_char_gte_lit1(0x03);
+
+  char0 = -2;
+  c_char_gte_lit1(0x01);
+
+  char0 = -0x40;
+  c_char_gte_lit1(0x01);
+
+  char0 = -0x7e;
+  c_char_gte_lit1(0x01);
+
+  char0 = -0x7f;
+  c_char_gte_lit1(0x01);
+
+  char0 = 0x80;
+  c_char_gte_lit1(0x00);
+
+
+  /* Now test entire range */
+
+  for(char0=1; char0 != 0x7e; char0++)
+    c_char_gte_lit1(0x0f);
+
+  for(char0=-0x7f; char0 != -1; char0++)
+    c_char_gte_lit1(0x01);
+
+}
+
+
+void c_int_gte_lit1(unsigned char expected_result)
+{
+  result = 0;
+
+  if(int0 >= 0)
+    result |= 1;
+
+  if(int0 >= 1)
+    result |= 2;
+
+
+  if(int0 >= 0xff)
+    result |= 4;
+
+  if(int0 >= 0x100)
+    result |= 8;
+
+  if(int0 >= 0x0101)
+    result |= 0x10;
+  
+  if(int0 >= 0x01ff)
+    result |= 0x20;
+  
+  if(int0 >= 0x0200)
+    result |= 0x40;
+
+  if(int0 >= 0x0201)
+    result |= 0x80;
+
+  if(result != expected_result)
+    failures=1;
+
+}
+
+
+void int_compare1(void)
+{
+  int0 = -1;
+  c_int_gte_lit1(0x00);
+
+  int0 = 0;
+  c_int_gte_lit1(0x01);
+
+  int0 = 1;
+  c_int_gte_lit1(0x03);
+
+  int0 = 2;
+  c_int_gte_lit1(0x03);
+
+  int0 = 0xfe;
+  c_int_gte_lit1(0x03);
+
+  int0 = 0xff;
+  c_int_gte_lit1(0x07);
+
+  int0 = 0x100;
+  c_int_gte_lit1(0x0f);
+
+  int0 = 0x101;
+  c_int_gte_lit1(0x1f);
+
+  int0 = 0x102;
+  c_int_gte_lit1(0x1f);
+
+  int0 = 0x1fe;
+  c_int_gte_lit1(0x1f);
+
+  int0 = 0x1ff;
+  c_int_gte_lit1(0x3f);
+
+  int0 = 0x200;
+  c_int_gte_lit1(0x7f);
+
+  int0 = 0x201;
+  c_int_gte_lit1(0xff);
+
+  int0 = 0x7f00;
+  c_int_gte_lit1(0xff);
+
+  /* now check contiguous ranges */
+
+  for(int0 = -0x7fff; int0 != -1; int0++)
+    c_int_gte_lit1(0x00);
+
+  for(int0 = 1; int0 != 0xff; int0++)
+    c_int_gte_lit1(0x03);
+
+  for(int0 = 0x201; int0 != 0x7fff; int0++)
+    c_int_gte_lit1(0xff);
+
+}
+
+
+void c_int_gte_lit2(unsigned char expected_result)
+{
+  result = 0;
+
+  if(int0 >= -0x7fff)
+    result |= 1;
+
+  if(int0 >= -0x7f00)
+    result |= 2;
+
+  if(int0 >= -0x7eff)
+    result |= 4;
+
+  if(int0 >= -0x7e00)
+    result |= 8;
+
+  if(int0 >= -0x0101)
+    result |= 0x10;
+  
+  if(int0 >= -0x0100)
+    result |= 0x20;
+  
+  if(int0 >= -0xff)
+    result |= 0x40;
+
+  if(int0 >= -1)
+    result |= 0x80;
+
+  if(result != expected_result)
+    failures=1;
+}
+
+void int_compare2(void)
+{
+  int0 = -0x7fff;
+  c_int_gte_lit2(0x01);
+
+  int0 = -0x7f00;
+  c_int_gte_lit2(0x03);
+
+  int0 = -0x7eff;
+  c_int_gte_lit2(0x07);
+
+  int0 = -0x7e00;
+  c_int_gte_lit2(0x0f);
+
+  int0 = -0x7dff;
+  c_int_gte_lit2(0x0f);
+
+  int0 = -0x4567;
+  c_int_gte_lit2(0x0f);
+
+  int0 = -0x200;
+  c_int_gte_lit2(0x0f);
+
+  int0 = -0x102;
+  c_int_gte_lit2(0x0f);
+
+  int0 = -0x101;
+  c_int_gte_lit2(0x1f);
+
+  int0 = -0x100;
+  c_int_gte_lit2(0x3f);
+
+  int0 = -0xff;
+  c_int_gte_lit2(0x7f);
+
+  int0 = -0x02;
+  c_int_gte_lit2(0x7f);
+
+  int0 = -0x01;
+  c_int_gte_lit2(0xff);
+
+  int0 = 0;
+  c_int_gte_lit2(0xff);
+
+  int0 = 1;
+  c_int_gte_lit2(0xff);
+
+  int0 = 0x7fff;
+  c_int_gte_lit2(0xff);
+
+  /* now check contiguous ranges */
+
+  for(int0 = -0x7fff; int0 != -0x7f00; int0++)
+    c_int_gte_lit2(0x01);
+
+  for(int0 = -0x7e00; int0 != -0x101; int0++)
+    c_int_gte_lit2(0x0f);
+
+  for(int0 = -1; int0 != 0x7fff; int0++)
+    c_int_gte_lit2(0xff);
+
+}
+
+
+
+
+void
+main (void)
+{
+  char_compare();
+  int_compare1();
+  int_compare2();
+
+  success = failures;
+  done ();
+}
index 3ea4bd6dbba105ada41f392503acf1a97a49a2b1..fb665c7ef04e411e080394d8ccf6878c5c04b8b7 100644 (file)
@@ -12,8 +12,8 @@ unsigned char dummy = 0;
 unsigned char result = 0;
 
 //bit bit0 = 0;
-long int0 = 0;
-long int1 = 0;
+int int0 = 0;
+int int1 = 0;
 signed char char0 = 0;
 signed char char1 = 0;
 char long0 = 0;
index eab3ffd7f32a4d7dbc41016e1c67616a8ef46b05..838d16bc8c4adbeaaac9f7707f058e952300bb87 100644 (file)
@@ -12,8 +12,8 @@ unsigned char dummy = 0;
 unsigned char result = 0;
 
 //bit bit0 = 0;
-long int0 = 0;
-long int1 = 0;
+int int0 = 0;
+int int1 = 0;
 unsigned char uchar0 = 0;
 unsigned char uchar1 = 0;
 signed char char0 = 0;
diff --git a/src/regression/compare9.c b/src/regression/compare9.c
new file mode 100644 (file)
index 0000000..6e4fa3c
--- /dev/null
@@ -0,0 +1,294 @@
+// Signed comparisons of the form:  (variable<=LIT)
+//
+// This regression test exercises all of the boundary
+// conditions in literal less than or equal comparisons. There
+// are numerous opportunities to optimize these comparison
+// and each one has an astonishing capability of failing
+// a boundary condition.
+
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
+unsigned char result = 0;
+
+int int0 = 0;
+int int1 = 0;
+signed char char0 = 0;
+signed char char1 = 0;
+
+void
+done ()
+{
+  dummy++;
+}
+
+
+void c_char_lte_lit1(unsigned char expected_result)
+{
+  result = 0;
+
+  if(char0 <= -0x7f)
+    result |= 1;
+
+  if(char0 <= -1)
+    result |= 2;
+
+  if(char0 <= 0)
+    result |= 4;
+
+  if(char0 <= 1)
+    result |= 8;
+
+  if(char0 <= 0x7f)
+    result |= 0x10;
+  
+  if(result != expected_result)
+    failures++;
+}
+
+
+void char_compare(void)
+{
+  char0 = 0x7f;
+  c_char_lte_lit1(0x10);
+
+  char0 = 0x7e;
+  c_char_lte_lit1(0x10);
+
+  char0 = 0x40;
+  c_char_lte_lit1(0x10);
+
+  char0 = 0x2;
+  c_char_lte_lit1(0x10);
+
+  char0 = 0x1;
+  c_char_lte_lit1(0x18);
+
+  char0 = 0;
+  c_char_lte_lit1(0x1c);
+
+  char0 = -1;
+  c_char_lte_lit1(0x1e);
+
+  char0 = -2;
+  c_char_lte_lit1(0x1e);
+
+  char0 = -0x40;
+  c_char_lte_lit1(0x1e);
+
+  char0 = -0x7e;
+  c_char_lte_lit1(0x1e);
+
+  char0 = -0x7f;
+  c_char_lte_lit1(0x1f);
+
+  char0 = 0x80;
+  //  c_char_lte_lit1(0x1f);
+
+
+  /* Now test entire range */
+
+  for(char0=2; char0 != 0x7f; char0++)
+    c_char_lte_lit1(0x10);
+
+
+  for(char0=-0x7e; char0 != 0; char0++)
+    c_char_lte_lit1(0x1e);
+
+
+}
+
+void c_int_lte_lit1(unsigned char expected_result)
+{
+  result = 0;
+
+  if(int0 <= 0)
+    result |= 1;
+
+  if(int0 <= 1)
+    result |= 2;
+
+
+  if(int0 <= 0xff)
+    result |= 4;
+
+  if(int0 <= 0x100)
+    result |= 8;
+
+  if(int0 <= 0x0101)
+    result |= 0x10;
+  
+  if(int0 <= 0x01ff)
+    result |= 0x20;
+  
+  if(int0 <= 0x0200)
+    result |= 0x40;
+
+  if(int0 <= 0x0201)
+    result |= 0x80;
+
+  if(result != expected_result)
+    failures=1;
+
+}
+
+
+void int_compare1(void)
+{
+  int0 = -1;
+  c_int_lte_lit1(0xff);
+
+  int0 = 0;
+  c_int_lte_lit1(0xff);
+
+  int0 = 1;
+  c_int_lte_lit1(0xfe);
+
+  int0 = 2;
+  c_int_lte_lit1(0xfc);
+
+  int0 = 0xfe;
+  c_int_lte_lit1(0xfc);
+
+  int0 = 0xff;
+  c_int_lte_lit1(0xfc);
+
+  int0 = 0x100;
+  c_int_lte_lit1(0xf8);
+
+  int0 = 0x101;
+  c_int_lte_lit1(0xf0);
+
+  int0 = 0x1fe;
+  c_int_lte_lit1(0xe0);
+
+  int0 = 0x1ff;
+  c_int_lte_lit1(0xe0);
+
+  int0 = 0x200;
+  c_int_lte_lit1(0xc0);
+
+  int0 = 0x201;
+  c_int_lte_lit1(0x80);
+
+  int0 = 0x7f00;
+  c_int_lte_lit1(0x0);
+
+  /* now check contiguous ranges */
+
+  for(int0 = -0x7fff; int0 != 1; int0++)
+    c_int_lte_lit1(0xff);
+
+  for(int0 = 2; int0 != 0xff; int0++)
+    c_int_lte_lit1(0xfc);
+
+  for(int0 = 0x202; int0 != 0x7fff; int0++)
+    c_int_lte_lit1(0);
+
+}
+
+
+
+void c_int_lte_lit2(unsigned char expected_result)
+{
+  result = 0;
+
+  if(int0 <= -0x7fff)
+    result |= 1;
+
+  if(int0 <= -0x7f00)
+    result |= 2;
+
+  if(int0 <= -0x7eff)
+    result |= 4;
+
+  if(int0 <= -0x7e00)
+    result |= 8;
+
+  if(int0 <= -0x0101)
+    result |= 0x10;
+  
+  if(int0 <= -0x0100)
+    result |= 0x20;
+  
+  if(int0 <= -0xff)
+    result |= 0x40;
+
+  if(int0 <= -1)
+    result |= 0x80;
+
+  if(result != expected_result)
+    failures=1;
+}
+
+void int_compare2(void)
+{
+  int0 = -0x7fff;
+  c_int_lte_lit2(0xff);
+
+  int0 = -0x7f00;
+  c_int_lte_lit2(0xfe);
+
+  int0 = -0x7eff;
+  c_int_lte_lit2(0xfc);
+
+  int0 = -0x7e00;
+  c_int_lte_lit2(0xf8);
+
+  int0 = -0x4567;
+  c_int_lte_lit2(0xf0);
+
+  int0 = -0x200;
+  c_int_lte_lit2(0xf0);
+
+  int0 = -0x102;
+  c_int_lte_lit2(0xf0);
+
+  int0 = -0x101;
+  c_int_lte_lit2(0xf0);
+
+  int0 = -0x100;
+  c_int_lte_lit2(0xe0);
+
+  int0 = -0xff;
+  c_int_lte_lit2(0xc0);
+
+  int0 = -0x02;
+  c_int_lte_lit2(0x80);
+
+  int0 = -0x01;
+  c_int_lte_lit2(0x80);
+
+  int0 = 0;
+  c_int_lte_lit2(0x00);
+
+  int0 = 1;
+  c_int_lte_lit2(0x00);
+
+  int0 = 0x7fff;
+  c_int_lte_lit2(0x00);
+
+  /* now check contiguous ranges */
+
+  for(int0 = -0x7ffe; int0 != -0x7f00; int0++)
+    c_int_lte_lit2(0xfe);
+
+  for(int0 = -0x7dff; int0 != -0x101; int0++)
+    c_int_lte_lit2(0xf0);
+
+  for(int0 = 0; int0 != 0x7fff; int0++)
+    c_int_lte_lit2(0);
+
+}
+
+
+void
+main (void)
+{
+  char_compare();
+  int_compare1();
+  int_compare2();
+
+  success = failures;
+  done ();
+}