commit b5fe10c6fb6606d271bc75e2245a801286f91bb4
parent 0e5ae348472d5ffb37f27761e190c6208554cb9c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 18 Mar 2015 07:02:14 +0000
Convert additions to increments
When the immediate value is small is better to use increments instead
of an addition.
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/cc2/cgen.c b/cc2/cgen.c
@@ -243,6 +243,7 @@ static void
add(Node *np)
{
Node *lp = np->left, *rp = np->right;
+ uint8_t i;
if (rp->op == REG || lp->op == CONST) {
conmute(np);
@@ -300,7 +301,17 @@ add(Node *np)
abort();
}
add_A:
+ if (rp->op == CONST) {
+ if ((i = rp->sym->u.imm) == 0)
+ goto update_A;
+ if (i < 4) {
+ while (i--)
+ code(INC, lp, NULL);
+ goto update_A;
+ }
+ }
code(ADD, lp, rp);
+ update_A:
np->op = REG;
np->reg = A;
break;