Indented some comments .
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 21 Dec 2001 05:09:25 +0000 (05:09 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 21 Dec 2001 05:09:25 +0000 (05:09 +0000)
Optimized unsigned less than & greater than compares

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

src/SDCCast.c

index cd93f35b4f4173b883b0006b587c5d19843a4fe7..0152f09f1b40eabf5936dd18de2273ad94f26e27 100644 (file)
@@ -1841,10 +1841,10 @@ decorateType (ast * tree)
 
   switch (tree->opval.op)
     {
-           /*------------------------------------------------------------------*/
-           /*----------------------------*/
-           /*        array node          */
-           /*----------------------------*/
+       /*------------------------------------------------------------------*/
+       /*----------------------------*/
+       /*        array node          */
+       /*----------------------------*/
     case '[':
 
       /* determine which is the array & which the index */
@@ -1951,10 +1951,10 @@ decorateType (ast * tree)
 
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*  ++/-- operation           */
-/*----------------------------*/
+      /*----------------------------*/
     case INC_OP:               /* incerement operator unary so left only */
     case DEC_OP:
       {
@@ -1970,10 +1970,10 @@ decorateType (ast * tree)
        return tree;
       }
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*  bitwise and               */
-/*----------------------------*/
+      /*----------------------------*/
     case '&':                  /* can be unary   */
       /* if right is NULL then unary operation  */
       if (tree->right)         /* not an unary operation */
@@ -2020,10 +2020,10 @@ decorateType (ast * tree)
          return tree;
        }
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*  address of                */
-/*----------------------------*/
+      /*----------------------------*/
       p = newLink ();
       p->class = DECLARATOR;
       /* if bit field then error */
@@ -2089,10 +2089,10 @@ decorateType (ast * tree)
       TLVAL (tree) = 1;
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*  bitwise or                */
-/*----------------------------*/
+      /*----------------------------*/
     case '|':
       /* if the rewrite succeeds then don't go any furthur */
       {
@@ -2100,10 +2100,10 @@ decorateType (ast * tree)
        if (wtree != tree)
          return decorateType (wtree);
       }
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*  bitwise xor               */
-/*----------------------------*/
+      /*----------------------------*/
     case '^':
       if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
        {
@@ -2134,10 +2134,10 @@ decorateType (ast * tree)
                               computeType (LTYPE (tree),
                                            RTYPE (tree)));
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*  division                  */
-/*----------------------------*/
+      /*----------------------------*/
     case '/':
       if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
        {
@@ -2162,10 +2162,10 @@ decorateType (ast * tree)
                                            RTYPE (tree)));
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*            modulus         */
-/*----------------------------*/
+      /*----------------------------*/
     case '%':
       if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
        {
@@ -2195,10 +2195,10 @@ decorateType (ast * tree)
                                            RTYPE (tree)));
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
-/*  address dereference       */
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
+      /*  address dereference       */
+      /*----------------------------*/
     case '*':                  /* can be unary  : if right is null then unary operation */
       if (!tree->right)
        {
@@ -2220,10 +2220,10 @@ decorateType (ast * tree)
          return tree;
        }
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*      multiplication        */
-/*----------------------------*/
+      /*----------------------------*/
       if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
        {
          werror (E_INVALID_OP, "multiplication");
@@ -2266,10 +2266,10 @@ decorateType (ast * tree)
       }
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*    unary '+' operator      */
-/*----------------------------*/
+      /*----------------------------*/
     case '+':
       /* if unary plus */
       if (!tree->right)
@@ -2294,10 +2294,10 @@ decorateType (ast * tree)
          return tree;
        }
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*      addition              */
-/*----------------------------*/
+      /*----------------------------*/
 
       /* this is not a unary operation */
       /* if both pointers then problem */
@@ -2356,10 +2356,10 @@ decorateType (ast * tree)
                                              RTYPE (tree)));
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*      unary '-'             */
-/*----------------------------*/
+      /*----------------------------*/
     case '-':                  /* can be unary   */
       /* if right is null then unary */
       if (!tree->right)
@@ -2386,10 +2386,10 @@ decorateType (ast * tree)
          return tree;
        }
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*    subtraction             */
-/*----------------------------*/
+      /*----------------------------*/
 
       if (!(IS_PTR (LTYPE (tree)) ||
            IS_ARRAY (LTYPE (tree)) ||
@@ -2456,10 +2456,10 @@ decorateType (ast * tree)
       LRVAL (tree) = RRVAL (tree) = 1;
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*    compliment              */
-/*----------------------------*/
+      /*----------------------------*/
     case '~':
       /* can be only integral type */
       if (!IS_INTEGRAL (LTYPE (tree)))
@@ -2481,10 +2481,10 @@ decorateType (ast * tree)
       COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*           not              */
-/*----------------------------*/
+      /*----------------------------*/
     case '!':
       /* can be pointer */
       if (!IS_ARITHMETIC (LTYPE (tree)) &&
@@ -2508,10 +2508,10 @@ decorateType (ast * tree)
       TTYPE (tree) = TETYPE (tree) = newCharLink ();
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*           shift            */
-/*----------------------------*/
+      /*----------------------------*/
     case RRC:
     case RLC:
       TTYPE (tree) = LTYPE (tree);
@@ -2643,10 +2643,10 @@ decorateType (ast * tree)
 
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*       logical &&, ||       */
-/*----------------------------*/
+      /*----------------------------*/
     case AND_OP:
     case OR_OP:
       /* each must me arithmetic type or be a pointer */
@@ -2683,10 +2683,10 @@ decorateType (ast * tree)
       TTYPE (tree) = TETYPE (tree) = newCharLink ();
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*     comparison operators   */
-/*----------------------------*/
+      /*----------------------------*/
     case '>':
     case '<':
     case LE_OP:
@@ -2731,7 +2731,18 @@ decorateType (ast * tree)
                goto errorTreeReturn;
              }
        }
+      /* if unsigned value < 0  then always false */
+      /* if (unsigned value) > 0 then (unsigned value) */
+      if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree)) && 
+         ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0) {
 
+         if (tree->opval.op == '<') {
+             return tree->right;
+         }
+         if (tree->opval.op == '>') {
+             return tree->left;
+         }
+      }
       /* if they are both literal then */
       /* rewrite the tree */
       if (IS_LITERAL (RTYPE (tree)) &&
@@ -2750,10 +2761,10 @@ decorateType (ast * tree)
       TTYPE (tree) = TETYPE (tree) = newCharLink ();
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*             sizeof         */
-/*----------------------------*/
+      /*----------------------------*/
     case SIZEOF:               /* evaluate wihout code generation */
       /* change the type to a integer */
       tree->type = EX_VALUE;
@@ -2872,10 +2883,10 @@ decorateType (ast * tree)
       return tree;
 
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*    assignment operators    */
-/*----------------------------*/
+      /*----------------------------*/
     case MUL_ASSIGN:
     case DIV_ASSIGN:
       /* for these it must be both must be integral */
@@ -2927,10 +2938,10 @@ decorateType (ast * tree)
 
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*    -= operator             */
-/*----------------------------*/
+      /*----------------------------*/
     case SUB_ASSIGN:
       if (!(IS_PTR (LTYPE (tree)) ||
            IS_ARITHMETIC (LTYPE (tree))))
@@ -2962,10 +2973,10 @@ decorateType (ast * tree)
 
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*          += operator       */
-/*----------------------------*/
+      /*----------------------------*/
     case ADD_ASSIGN:
       /* this is not a unary operation */
       /* if both pointers then problem */
@@ -3005,10 +3016,10 @@ decorateType (ast * tree)
 
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*      straight assignemnt   */
-/*----------------------------*/
+      /*----------------------------*/
     case '=':
       /* cannot be an aggregate */
       if (IS_AGGREGATE (LTYPE (tree)))
@@ -3054,18 +3065,18 @@ decorateType (ast * tree)
 
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*      comma operator        */
-/*----------------------------*/
+      /*----------------------------*/
     case ',':
       TETYPE (tree) = getSpec (TTYPE (tree) = RTYPE (tree));
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*       function call        */
-/*----------------------------*/
+      /*----------------------------*/
     case CALL:
       parmNumber = 1;
 
@@ -3086,10 +3097,10 @@ decorateType (ast * tree)
       TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next);
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*     return statement       */
-/*----------------------------*/
+      /*----------------------------*/
     case RETURN:
       if (!tree->right)
        goto voidcheck;
@@ -3132,10 +3143,10 @@ decorateType (ast * tree)
       TTYPE (tree) = TETYPE (tree) = NULL;
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*     switch statement       */
-/*----------------------------*/
+      /*----------------------------*/
     case SWITCH:
       /* the switch value must be an integer */
       if (!IS_INTEGRAL (LTYPE (tree)))
@@ -3147,10 +3158,10 @@ decorateType (ast * tree)
       TTYPE (tree) = TETYPE (tree) = NULL;
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /* ifx Statement              */
-/*----------------------------*/
+      /*----------------------------*/
     case IFX:
       tree->left = backPatchLabels (tree->left,
                                    tree->trueLabel,
@@ -3158,10 +3169,10 @@ decorateType (ast * tree)
       TTYPE (tree) = TETYPE (tree) = NULL;
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /* for Statement              */
-/*----------------------------*/
+      /*----------------------------*/
     case FOR:
 
       decorateType (resolveSymbols (AST_FOR (tree, initExpr)));