mirror of
https://github.com/cc65/cc65.git
synced 2025-01-12 02:30:44 +00:00
Added another optimization step
git-svn-id: svn://svn.cc65.org/cc65/trunk@3732 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
7736aac1e2
commit
e81d5ec00a
@ -1395,6 +1395,86 @@ static unsigned OptPtrLoad7 (CodeSeg* S)
|
||||
|
||||
|
||||
static unsigned OptPtrLoad8 (CodeSeg* S)
|
||||
/* Search for the sequence:
|
||||
*
|
||||
* lda zp
|
||||
* ldx zp+1
|
||||
* (anything that doesn't change a/x)
|
||||
* ldy xx
|
||||
* jsr ldauidx
|
||||
*
|
||||
* and replace it by:
|
||||
*
|
||||
* lda zp
|
||||
* ldx zp+1
|
||||
* (anything that doesn't change a/x)
|
||||
* ldy xx
|
||||
* ldx #$00
|
||||
* lda (zp),y
|
||||
*
|
||||
* Must execute before OptPtrLoad10!
|
||||
*/
|
||||
{
|
||||
unsigned Changes = 0;
|
||||
|
||||
/* Generate register info */
|
||||
CS_GenRegInfo (S);
|
||||
|
||||
/* Walk over the entries */
|
||||
unsigned I = 0;
|
||||
while (I < CS_GetEntryCount (S)) {
|
||||
|
||||
CodeEntry* L[5];
|
||||
unsigned Len;
|
||||
|
||||
/* Get next entry */
|
||||
L[0] = CS_GetEntry (S, I);
|
||||
|
||||
/* Check for the sequence */
|
||||
if (L[0]->OPC == OP65_LDA && L[0]->AM == AM65_ZP &&
|
||||
CS_GetEntries (S, L+1, I+1, 4) &&
|
||||
!CS_RangeHasLabel (S, I+1, 4) &&
|
||||
L[1]->OPC == OP65_LDX && L[1]->AM == AM65_ZP &&
|
||||
(Len = strlen (L[0]->Arg)) > 0 &&
|
||||
strncmp (L[0]->Arg, L[1]->Arg, Len) == 0 &&
|
||||
strcmp (L[1]->Arg + Len, "+1") == 0 &&
|
||||
(L[2]->Chg & REG_AX) == 0 &&
|
||||
L[3]->OPC == OP65_LDY &&
|
||||
CE_IsCallTo (L[4], "ldauidx")) {
|
||||
|
||||
CodeEntry* X;
|
||||
|
||||
/* ldx #$00 */
|
||||
X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[3]->LI);
|
||||
CS_InsertEntry (S, X, I+5);
|
||||
|
||||
/* lda (zp),y */
|
||||
X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, L[0]->Arg, 0, L[3]->LI);
|
||||
CS_InsertEntry (S, X, I+6);
|
||||
|
||||
/* Remove the old code */
|
||||
CS_DelEntry (S, I+4);
|
||||
|
||||
/* Remember, we had changes */
|
||||
++Changes;
|
||||
|
||||
}
|
||||
|
||||
/* Next entry */
|
||||
++I;
|
||||
|
||||
}
|
||||
|
||||
/* Free the register info */
|
||||
CS_FreeRegInfo (S);
|
||||
|
||||
/* Return the number of changes made */
|
||||
return Changes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned OptPtrLoad9 (CodeSeg* S)
|
||||
/* Search for the sequence:
|
||||
*
|
||||
* lda zp
|
||||
@ -1472,7 +1552,7 @@ static unsigned OptPtrLoad8 (CodeSeg* S)
|
||||
|
||||
|
||||
|
||||
static unsigned OptPtrLoad9 (CodeSeg* S)
|
||||
static unsigned OptPtrLoad10 (CodeSeg* S)
|
||||
/* Search for the sequence
|
||||
*
|
||||
* ldy ...
|
||||
@ -1848,8 +1928,9 @@ static OptFunc DOptPtrLoad4 = { OptPtrLoad4, "OptPtrLoad4", 100, 0,
|
||||
static OptFunc DOptPtrLoad5 = { OptPtrLoad5, "OptPtrLoad5", 92, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad6 = { OptPtrLoad6, "OptPtrLoad6", 50, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad7 = { OptPtrLoad7, "OptPtrLoad7", 65, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad8 = { OptPtrLoad8, "OptPtrLoad8", 86, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad9 = { OptPtrLoad9, "OptPtrLoad9", 100, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad8 = { OptPtrLoad8, "OptPtrLoad8", 108, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad9 = { OptPtrLoad9, "OptPtrLoad9", 86, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrLoad10 = { OptPtrLoad10, "OptPtrLoad10", 100, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrStore1 = { OptPtrStore1, "OptPtrStore1", 100, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPtrStore2 = { OptPtrStore2, "OptPtrStore2", 40, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptPush1 = { OptPush1, "OptPush1", 65, 0, 0, 0, 0, 0 };
|
||||
@ -1914,6 +1995,7 @@ static OptFunc* OptFuncs[] = {
|
||||
&DOptNegAX4,
|
||||
&DOptPrecalc,
|
||||
&DOptPtrLoad1,
|
||||
&DOptPtrLoad10,
|
||||
&DOptPtrLoad2,
|
||||
&DOptPtrLoad3,
|
||||
&DOptPtrLoad4,
|
||||
@ -2194,6 +2276,7 @@ static unsigned RunOptGroup1 (CodeSeg* S)
|
||||
Changes += RunOptFunc (S, &DOptPtrLoad6, 1);
|
||||
Changes += RunOptFunc (S, &DOptPtrLoad7, 1);
|
||||
Changes += RunOptFunc (S, &DOptPtrLoad8, 1);
|
||||
Changes += RunOptFunc (S, &DOptPtrLoad9, 1);
|
||||
Changes += RunOptFunc (S, &DOptNegAX1, 1);
|
||||
Changes += RunOptFunc (S, &DOptNegAX2, 1);
|
||||
Changes += RunOptFunc (S, &DOptNegAX3, 1);
|
||||
@ -2245,7 +2328,7 @@ static unsigned RunOptGroup3 (CodeSeg* S)
|
||||
do {
|
||||
C = 0;
|
||||
|
||||
C += RunOptFunc (S, &DOptPtrLoad9, 1);
|
||||
C += RunOptFunc (S, &DOptPtrLoad10, 1);
|
||||
C += RunOptFunc (S, &DOptNegA1, 1);
|
||||
C += RunOptFunc (S, &DOptNegA2, 1);
|
||||
C += RunOptFunc (S, &DOptSub1, 1);
|
||||
@ -2320,7 +2403,7 @@ static unsigned RunOptGroup5 (CodeSeg* S)
|
||||
/* Run another round of pattern replacements. These are done late, since there
|
||||
* may be better replacements before.
|
||||
*/
|
||||
{
|
||||
{
|
||||
unsigned Changes = 0;
|
||||
|
||||
Changes += RunOptFunc (S, &DOptPush1, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user