From b02838439c0c4a237e6094b71415193e44485be4 Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 22 Feb 2021 12:33:26 +0800 Subject: [PATCH] Changed g_addaddr_local() codegen to reduce code size. --- src/cc65/codegen.c | 51 +++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index bf7c900ab..f8a1dcdf6 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -2112,29 +2112,38 @@ void g_addaddr_local (unsigned flags attribute ((unused)), int offs) /* Add the offset */ offs -= StackPtr; - if (offs != 0) { - /* We cannot address more then 256 bytes of locals anyway */ - L = GetLocalLabel(); - CheckLocalOffs (offs); - AddCodeLine ("clc"); - AddCodeLine ("adc #$%02X", offs & 0xFF); - /* Do also skip the CLC insn below */ - AddCodeLine ("bcc %s", LocalLabelName (L)); - AddCodeLine ("inx"); - } + if (IS_Get (&CodeSizeFactor) <= 100) { + if (offs != 0) { + /* We cannot address more then 256 bytes of locals anyway */ + g_inc (CF_INT | CF_CONST, offs); + } + /* Add the current stackpointer value */ + AddCodeLine ("jsr leaaxsp"); + } else { + if (offs != 0) { + /* We cannot address more then 256 bytes of locals anyway */ + L = GetLocalLabel(); + CheckLocalOffs (offs); + AddCodeLine ("clc"); + AddCodeLine ("adc #$%02X", offs & 0xFF); + /* Do also skip the CLC insn below */ + AddCodeLine ("bcc %s", LocalLabelName (L)); + AddCodeLine ("inx"); + } - /* Add the current stackpointer value */ - AddCodeLine ("clc"); - if (L != 0) { - /* Label was used above */ - g_defcodelabel (L); + /* Add the current stackpointer value */ + AddCodeLine ("clc"); + if (L != 0) { + /* Label was used above */ + g_defcodelabel (L); + } + AddCodeLine ("adc sp"); + AddCodeLine ("tay"); + AddCodeLine ("txa"); + AddCodeLine ("adc sp+1"); + AddCodeLine ("tax"); + AddCodeLine ("tya"); } - AddCodeLine ("adc sp"); - AddCodeLine ("tay"); - AddCodeLine ("txa"); - AddCodeLine ("adc sp+1"); - AddCodeLine ("tax"); - AddCodeLine ("tya"); }