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
switch (tree->opval.op)
{
switch (tree->opval.op)
{
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* array node */
- /*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* array node */
+ /*----------------------------*/
case '[':
/* determine which is the array & which the index */
case '[':
/* determine which is the array & which the index */
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case INC_OP: /* incerement operator unary so left only */
case DEC_OP:
{
case INC_OP: /* incerement operator unary so left only */
case DEC_OP:
{
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '&': /* can be unary */
/* if right is NULL then unary operation */
if (tree->right) /* not an unary operation */
case '&': /* can be unary */
/* if right is NULL then unary operation */
if (tree->right) /* not an unary operation */
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
p = newLink ();
p->class = DECLARATOR;
/* if bit field then error */
p = newLink ();
p->class = DECLARATOR;
/* if bit field then error */
TLVAL (tree) = 1;
return tree;
TLVAL (tree) = 1;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '|':
/* if the rewrite succeeds then don't go any furthur */
{
case '|':
/* if the rewrite succeeds then don't go any furthur */
{
if (wtree != tree)
return decorateType (wtree);
}
if (wtree != tree)
return decorateType (wtree);
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '^':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
case '^':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
computeType (LTYPE (tree),
RTYPE (tree)));
computeType (LTYPE (tree),
RTYPE (tree)));
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '/':
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
{
case '/':
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
{
RTYPE (tree)));
return tree;
RTYPE (tree)));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '%':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
case '%':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
RTYPE (tree)));
return tree;
RTYPE (tree)));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
-/* address dereference */
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* address dereference */
+ /*----------------------------*/
case '*': /* can be unary : if right is null then unary operation */
if (!tree->right)
{
case '*': /* can be unary : if right is null then unary operation */
if (!tree->right)
{
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
{
werror (E_INVALID_OP, "multiplication");
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
{
werror (E_INVALID_OP, "multiplication");
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '+':
/* if unary plus */
if (!tree->right)
case '+':
/* if unary plus */
if (!tree->right)
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
/* this is not a unary operation */
/* if both pointers then problem */
/* this is not a unary operation */
/* if both pointers then problem */
RTYPE (tree)));
return tree;
RTYPE (tree)));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '-': /* can be unary */
/* if right is null then unary */
if (!tree->right)
case '-': /* can be unary */
/* if right is null then unary */
if (!tree->right)
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
if (!(IS_PTR (LTYPE (tree)) ||
IS_ARRAY (LTYPE (tree)) ||
if (!(IS_PTR (LTYPE (tree)) ||
IS_ARRAY (LTYPE (tree)) ||
LRVAL (tree) = RRVAL (tree) = 1;
return tree;
LRVAL (tree) = RRVAL (tree) = 1;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '~':
/* can be only integral type */
if (!IS_INTEGRAL (LTYPE (tree)))
case '~':
/* can be only integral type */
if (!IS_INTEGRAL (LTYPE (tree)))
COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
return tree;
COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case '!':
/* can be pointer */
if (!IS_ARITHMETIC (LTYPE (tree)) &&
case '!':
/* can be pointer */
if (!IS_ARITHMETIC (LTYPE (tree)) &&
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case RRC:
case RLC:
TTYPE (tree) = LTYPE (tree);
case RRC:
case RLC:
TTYPE (tree) = LTYPE (tree);
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case AND_OP:
case OR_OP:
/* each must me arithmetic type or be a pointer */
case AND_OP:
case OR_OP:
/* each must me arithmetic type or be a pointer */
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* comparison operators */
/* comparison operators */
-/*----------------------------*/
+ /*----------------------------*/
case '>':
case '<':
case LE_OP:
case '>':
case '<':
case LE_OP:
goto errorTreeReturn;
}
}
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)) &&
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) &&
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case SIZEOF: /* evaluate wihout code generation */
/* change the type to a integer */
tree->type = EX_VALUE;
case SIZEOF: /* evaluate wihout code generation */
/* change the type to a integer */
tree->type = EX_VALUE;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* assignment operators */
/* assignment operators */
-/*----------------------------*/
+ /*----------------------------*/
case MUL_ASSIGN:
case DIV_ASSIGN:
/* for these it must be both must be integral */
case MUL_ASSIGN:
case DIV_ASSIGN:
/* for these it must be both must be integral */
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case SUB_ASSIGN:
if (!(IS_PTR (LTYPE (tree)) ||
IS_ARITHMETIC (LTYPE (tree))))
case SUB_ASSIGN:
if (!(IS_PTR (LTYPE (tree)) ||
IS_ARITHMETIC (LTYPE (tree))))
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case ADD_ASSIGN:
/* this is not a unary operation */
/* if both pointers then problem */
case ADD_ASSIGN:
/* this is not a unary operation */
/* if both pointers then problem */
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* straight assignemnt */
/* straight assignemnt */
-/*----------------------------*/
+ /*----------------------------*/
case '=':
/* cannot be an aggregate */
if (IS_AGGREGATE (LTYPE (tree)))
case '=':
/* cannot be an aggregate */
if (IS_AGGREGATE (LTYPE (tree)))
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case ',':
TETYPE (tree) = getSpec (TTYPE (tree) = RTYPE (tree));
return tree;
case ',':
TETYPE (tree) = getSpec (TTYPE (tree) = RTYPE (tree));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case CALL:
parmNumber = 1;
case CALL:
parmNumber = 1;
TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next);
return tree;
TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next);
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case RETURN:
if (!tree->right)
goto voidcheck;
case RETURN:
if (!tree->right)
goto voidcheck;
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case SWITCH:
/* the switch value must be an integer */
if (!IS_INTEGRAL (LTYPE (tree)))
case SWITCH:
/* the switch value must be an integer */
if (!IS_INTEGRAL (LTYPE (tree)))
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case IFX:
tree->left = backPatchLabels (tree->left,
tree->trueLabel,
case IFX:
tree->left = backPatchLabels (tree->left,
tree->trueLabel,
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
-/*----------------------------*/
+ /*----------------------------*/
case FOR:
decorateType (resolveSymbols (AST_FOR (tree, initExpr)));
case FOR:
decorateType (resolveSymbols (AST_FOR (tree, initExpr)));