1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-16 18:08:04 +00:00

Add fast path for char postinc

This commit is contained in:
Lauri Kasanen 2017-05-06 13:20:55 +03:00
parent 18b0aaf9f2
commit 767f093ff8

View File

@ -1534,26 +1534,35 @@ static void PostInc (ExprDesc* Expr)
/* Get the data type */ /* Get the data type */
Flags = TypeOf (Expr->Type); Flags = TypeOf (Expr->Type);
/* Push the address if needed */ /* Fast path: char */
PushAddr (Expr); if ((Flags & CF_CHAR) == CF_CHAR && ED_GetLoc(Expr) & (E_LOC_GLOBAL | E_LOC_STATIC)) {
/* Fetch the value and save it (since it's the result of the expression) */ LoadExpr (CF_NONE, Expr);
LoadExpr (CF_NONE, Expr); AddCodeLine ("inc %s", ED_GetLabelName(Expr, 0));
g_save (Flags | CF_FORCECHAR);
/* If we have a pointer expression, increment by the size of the type */
if (IsTypePtr (Expr->Type)) {
g_inc (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1));
} else { } else {
g_inc (Flags | CF_CONST | CF_FORCECHAR, 1);
/* Push the address if needed */
PushAddr (Expr);
/* Fetch the value and save it (since it's the result of the expression) */
LoadExpr (CF_NONE, Expr);
g_save (Flags | CF_FORCECHAR);
/* If we have a pointer expression, increment by the size of the type */
if (IsTypePtr (Expr->Type)) {
g_inc (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1));
} else {
g_inc (Flags | CF_CONST | CF_FORCECHAR, 1);
}
/* Store the result back */
Store (Expr, 0);
/* Restore the original value in the primary register */
g_restore (Flags | CF_FORCECHAR);
} }
/* Store the result back */
Store (Expr, 0);
/* Restore the original value in the primary register */
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);
} }