mirror of
https://github.com/cc65/cc65.git
synced 2025-03-03 09:32:33 +00:00
Another minor improvement in compares.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4745 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ce886f4c5e
commit
477b77f528
@ -2029,6 +2029,10 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
/* Determine the signedness of the operands */
|
||||||
|
int LeftSigned = IsSignSigned (Expr->Type);
|
||||||
|
int RightSigned = IsSignSigned (Expr2.Type);
|
||||||
|
|
||||||
/* If the right hand side is constant, and the generator function
|
/* If the right hand side is constant, and the generator function
|
||||||
* expects the lhs in the primary, remove the push of the primary
|
* expects the lhs in the primary, remove the push of the primary
|
||||||
* now.
|
* now.
|
||||||
@ -2045,11 +2049,9 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
/* Determine the type of the operation. */
|
/* Determine the type of the operation. */
|
||||||
if (IsTypeChar (Expr->Type) && rconst) {
|
if (IsTypeChar (Expr->Type) && rconst) {
|
||||||
|
|
||||||
/* Left side is unsigned char, right side is constant */
|
/* Left side is unsigned char, right side is constant.
|
||||||
int LeftSigned = IsSignSigned (Expr->Type);
|
* Determine the minimum and maximum values
|
||||||
int RightSigned = IsSignSigned (Expr2.Type);
|
*/
|
||||||
|
|
||||||
/* Determine the minimum and maximum values */
|
|
||||||
int LeftMin, LeftMax;
|
int LeftMin, LeftMax;
|
||||||
if (LeftSigned) {
|
if (LeftSigned) {
|
||||||
LeftMin = -128;
|
LeftMin = -128;
|
||||||
@ -2111,11 +2113,6 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
WarnConstCompareResult ();
|
WarnConstCompareResult ();
|
||||||
RemoveCode (&Mark0);
|
RemoveCode (&Mark0);
|
||||||
goto Done;
|
goto Done;
|
||||||
} else if (!LeftSigned && Expr2.IVal == 0) {
|
|
||||||
/* We can replace this by a compare to zero, because
|
|
||||||
* the value of lhs may never be negative.
|
|
||||||
*/
|
|
||||||
GenFunc = g_eq;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2134,11 +2131,6 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
WarnConstCompareResult ();
|
WarnConstCompareResult ();
|
||||||
RemoveCode (&Mark0);
|
RemoveCode (&Mark0);
|
||||||
goto Done;
|
goto Done;
|
||||||
} else if (!LeftSigned && Expr2.IVal == 0) {
|
|
||||||
/* We can replace this by a compare to zero, because
|
|
||||||
* the value of lhs may never be negative.
|
|
||||||
*/
|
|
||||||
GenFunc = g_ne;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2165,7 +2157,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
if (rconst) {
|
if (rconst) {
|
||||||
flags |= CF_FORCECHAR;
|
flags |= CF_FORCECHAR;
|
||||||
}
|
}
|
||||||
if (IsSignUnsigned (Expr->Type)) {
|
if (!LeftSigned) {
|
||||||
flags |= CF_UNSIGNED;
|
flags |= CF_UNSIGNED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2173,6 +2165,59 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
flags |= g_typeadjust (ltype, rtype);
|
flags |= g_typeadjust (ltype, rtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the left side is an unsigned and the right is a constant,
|
||||||
|
* we may be able to change the compares to something more
|
||||||
|
* effective.
|
||||||
|
*/
|
||||||
|
if (!LeftSigned && rconst) {
|
||||||
|
|
||||||
|
switch (Tok) {
|
||||||
|
|
||||||
|
case TOK_LT:
|
||||||
|
if (Expr2.IVal == 1) {
|
||||||
|
/* An unsigned compare to one means that the value
|
||||||
|
* must be zero.
|
||||||
|
*/
|
||||||
|
GenFunc = g_eq;
|
||||||
|
Expr2.IVal = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOK_LE:
|
||||||
|
if (Expr2.IVal == 0) {
|
||||||
|
/* An unsigned compare to zero means that the value
|
||||||
|
* must be zero.
|
||||||
|
*/
|
||||||
|
GenFunc = g_eq;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOK_GE:
|
||||||
|
if (Expr2.IVal == 1) {
|
||||||
|
/* An unsigned compare to one means that the value
|
||||||
|
* must not be zero.
|
||||||
|
*/
|
||||||
|
GenFunc = g_ne;
|
||||||
|
Expr2.IVal = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOK_GT:
|
||||||
|
if (Expr2.IVal == 0) {
|
||||||
|
/* An unsigned compare to zero means that the value
|
||||||
|
* must not be zero.
|
||||||
|
*/
|
||||||
|
GenFunc = g_ne;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Generate code */
|
/* Generate code */
|
||||||
GenFunc (flags, Expr2.IVal);
|
GenFunc (flags, Expr2.IVal);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user