Merge pull request #425 from clbr/arrayaccess
Add fast paths for char postinc/dec
This commit is contained in:
@@ -1534,6 +1534,14 @@ static void PostInc (ExprDesc* Expr)
|
|||||||
/* Get the data type */
|
/* Get the data type */
|
||||||
Flags = TypeOf (Expr->Type);
|
Flags = TypeOf (Expr->Type);
|
||||||
|
|
||||||
|
/* Emit smaller code if a char variable is at a constant location */
|
||||||
|
if ((Flags & CF_CHAR) == CF_CHAR && ED_IsLocConst(Expr)) {
|
||||||
|
|
||||||
|
LoadExpr (CF_NONE, Expr);
|
||||||
|
AddCodeLine ("inc %s", ED_GetLabelName(Expr, 0));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
/* Push the address if needed */
|
/* Push the address if needed */
|
||||||
PushAddr (Expr);
|
PushAddr (Expr);
|
||||||
|
|
||||||
@@ -1553,6 +1561,7 @@ static void PostInc (ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Restore the original value in the primary register */
|
/* Restore the original value in the primary register */
|
||||||
g_restore (Flags | CF_FORCECHAR);
|
g_restore (Flags | CF_FORCECHAR);
|
||||||
|
}
|
||||||
|
|
||||||
/* The result is always an expression, no reference */
|
/* The result is always an expression, no reference */
|
||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
@@ -1581,6 +1590,14 @@ static void PostDec (ExprDesc* Expr)
|
|||||||
/* Get the data type */
|
/* Get the data type */
|
||||||
Flags = TypeOf (Expr->Type);
|
Flags = TypeOf (Expr->Type);
|
||||||
|
|
||||||
|
/* Emit smaller code if a char variable is at a constant location */
|
||||||
|
if ((Flags & CF_CHAR) == CF_CHAR && ED_IsLocConst(Expr)) {
|
||||||
|
|
||||||
|
LoadExpr (CF_NONE, Expr);
|
||||||
|
AddCodeLine ("dec %s", ED_GetLabelName(Expr, 0));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
/* Push the address if needed */
|
/* Push the address if needed */
|
||||||
PushAddr (Expr);
|
PushAddr (Expr);
|
||||||
|
|
||||||
@@ -1600,6 +1617,7 @@ static void PostDec (ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Restore the original value in the primary register */
|
/* Restore the original value in the primary register */
|
||||||
g_restore (Flags | CF_FORCECHAR);
|
g_restore (Flags | CF_FORCECHAR);
|
||||||
|
}
|
||||||
|
|
||||||
/* The result is always an expression, no reference */
|
/* The result is always an expression, no reference */
|
||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
|
|||||||
23
test/val/postincdec.c
Normal file
23
test/val/postincdec.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! char-sized post-increment and -decrement
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Lauri Kasanen
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned char val, array[2];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
val = 0;
|
||||||
|
array[0] = array[1] = 10;
|
||||||
|
|
||||||
|
array[val++] = 2;
|
||||||
|
array[val++] = 2;
|
||||||
|
--val;
|
||||||
|
array[val--] = 0;
|
||||||
|
array[val--] = 0;
|
||||||
|
|
||||||
|
return (array[0] == array[1] && array[0] == 0 && val == 0xff) ? 0 : 1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user