From: Lauri Kasanen Date: Sat, 6 May 2017 10:23:50 +0000 (+0300) Subject: Add fast path for char postdec X-Git-Tag: V2.17~147^2~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ead0338c0def811cb251090cc0851899a0cbdf8e;p=cc65 Add fast path for char postdec --- diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 502fd7a8e..e5c1a17b9 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1590,25 +1590,34 @@ static void PostDec (ExprDesc* Expr) /* Get the data type */ Flags = TypeOf (Expr->Type); - /* Push the address if needed */ - PushAddr (Expr); + /* Fast path: char */ + 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); - g_save (Flags | CF_FORCECHAR); + LoadExpr (CF_NONE, Expr); + AddCodeLine ("dec %s", ED_GetLabelName(Expr, 0)); - /* If we have a pointer expression, increment by the size of the type */ - if (IsTypePtr (Expr->Type)) { - g_dec (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1)); } else { - g_dec (Flags | CF_CONST | CF_FORCECHAR, 1); - } - /* Store the result back */ - Store (Expr, 0); + /* 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_dec (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1)); + } else { + g_dec (Flags | CF_CONST | CF_FORCECHAR, 1); + } - /* 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 */ ED_MakeRValExpr (Expr);