scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 7e5eb0d9f025aab0d247d0566f1a970cdb18ece9
parent cde05e319be1e511ff3dd66a15ba048e09876de3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 Mar 2015 11:49:15 +0000

Optimize the generation of the preambule

If the size of the stack frame is smaller than 6 bytes then is better
to use PUSH instructions that generate the ADD HL,SP sequence.

Diffstat:
Mcc2/cgen.c | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -350,21 +350,27 @@ void generate(void) { extern char odebug; - char frame = curfun->u.f.locals != 0 || odebug; + uint8_t i, size = curfun->u.f.locals; + char frame = size != 0 || odebug; if (frame) { - code(PUSH, NULL, regs[IX]); - code(MOV, regs[IX], regs[SP]); - code(MOV, regs[HL], imm(-curfun->u.f.locals, &l_int16)); - code(ADD, regs[HL], regs[SP]); - code(MOV, regs[SP], regs[HL]); + code(PUSH, NULL, &reg_IX); + code(MOV, &reg_IX, &reg_SP); + if (size > 6) { + code(MOV, &reg_HL, imm(-size, &l_int16)); + code(ADD, &reg_HL, &reg_SP); + code(MOV, &reg_SP, &reg_HL); + } else { + for (i = size; i != 0; i-= 2) + code(PUSH, NULL, &reg_HL); + } } apply(applycgen); if (frame) { - code(MOV, regs[SP], regs[IX]); - code(POP, regs[IX], NULL); + code(MOV, &reg_SP, &reg_IX); + code(POP, &reg_IX, NULL); code(RET, NULL, NULL); } }