From eed37235024a857b6ed957e88750ce8e57bf9120 Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 4 Dec 2000 23:34:28 +0000 Subject: [PATCH] Optimize local immidiate stores git-svn-id: svn://svn.cc65.org/cc65/trunk@556 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/optimize.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/cc65/optimize.c b/src/cc65/optimize.c index 5fa0ad561..55ebe9761 100644 --- a/src/cc65/optimize.c +++ b/src/cc65/optimize.c @@ -1719,8 +1719,42 @@ static void OptLoads (void) /* Remove the remaining lines */ FreeLines (L2[1], L2[2]); - } + /* Search for: + * + * ldx xx + * lda yy + * jsr stax0sp + * + * and replace it by: + * + * lda xx + * ldy #$01 + * sta (sp),y + * dey + * lda yy + * sta (sp),y + * + * provided that that the X register is not used later. This code + * sequence is four bytes longer, but a lot faster and it does not + * use the X register, so other loads may get removed later. + */ + } else if (LineMatch (L, "\tldx\t") && + GetNextCodeLines (L, L2, 2) && + LineMatch (L2 [0], "\tlda\t") && + LineFullMatch (L2 [1], "\tjsr\tstax0sp") && + !RegXUsed (L2[1])) { + + /* Found - replace it */ + L->Line[3] = 'a'; + L = NewLineAfter (L, "\tldy\t#$01"); + L = NewLineAfter (L, "\tsta\t(sp),y"); + L = NewLineAfter (L, "\tdey"); + L = NewLineAfter (L2[0], "\tsta\t(sp),y"); + + /* Remove the remaining line */ + FreeLine (L2[1]); + } /* All other patterns start with this one: */ if (!LineFullMatch (L, "\tldx\t#$00")) { -- 2.39.5