From 540bf5283639fc5a08505a891ac8db16ea4cc0f3 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Sun, 20 Sep 2015 17:51:04 -0400 Subject: simplify two loops with a pointer --- lisc/emit.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'lisc') diff --git a/lisc/emit.c b/lisc/emit.c index 116d0d2..fb4bc8d 100644 --- a/lisc/emit.c +++ b/lisc/emit.c @@ -306,7 +306,7 @@ emitfn(Fn *fn, FILE *f) { Blk *b, *s; Ins *i; - int r, j, c, fs; + int *r, c, fs; fprintf(f, ".text\n" @@ -320,11 +320,9 @@ emitfn(Fn *fn, FILE *f) fs = framesz(fn); if (fs) fprintf(f, "\tsub $%d, %%rsp\n", fs); - for (j=0; jreg & BIT(r)) - emitf(fn, f, "\tpush%w %R\n", 1, TMP(r)); - } + for (r=rclob; r-rclob < NRClob; r++) + if (fn->reg & BIT(*r)) + emitf(fn, f, "\tpush%w %R\n", 1, TMP(*r)); for (b=fn->start; b; b=b->link) { fprintf(f, ".L%s:\n", b->name); @@ -332,11 +330,9 @@ emitfn(Fn *fn, FILE *f) eins(*i, fn, f); switch (b->jmp.type) { case JRet: - for (j=NRClob; j>=0; j--) { - r = rclob[j]; - if (fn->reg & BIT(r)) - emitf(fn, f, "\tpop%w %R\n", 1, TMP(r)); - } + for (r=&rclob[NRClob]; r>rclob;) + if (fn->reg & BIT(*--r)) + emitf(fn, f, "\tpop%w %R\n", 1, TMP(*r)); fprintf(f, "\tleave\n" "\tret\n" -- cgit 1.4.1