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:
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, ®_IX);
+ code(MOV, ®_IX, ®_SP);
+ if (size > 6) {
+ code(MOV, ®_HL, imm(-size, &l_int16));
+ code(ADD, ®_HL, ®_SP);
+ code(MOV, ®_SP, ®_HL);
+ } else {
+ for (i = size; i != 0; i-= 2)
+ code(PUSH, NULL, ®_HL);
+ }
}
apply(applycgen);
if (frame) {
- code(MOV, regs[SP], regs[IX]);
- code(POP, regs[IX], NULL);
+ code(MOV, ®_SP, ®_IX);
+ code(POP, ®_IX, NULL);
code(RET, NULL, NULL);
}
}