1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-10 04:25:21 +00:00

New optimization

git-svn-id: svn://svn.cc65.org/cc65/trunk@551 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-12-04 21:28:36 +00:00
parent 0ab45f63f0
commit a05a5e5c38

View File

@@ -569,7 +569,7 @@ static int IsHint (const Line* L, const char* Hint)
static int IsCondJump (Line* L)
static int IsCondJump (const Line* L)
/* Return true if the line contains a conditional jump */
{
return (L->Line [0] == '\t' &&
@@ -581,7 +581,7 @@ static int IsCondJump (Line* L)
static int IsXAddrMode (Line* L)
static int IsXAddrMode (const Line* L)
/* Return true if the given line does use the X register */
{
unsigned Len = strlen (L->Line);
@@ -591,7 +591,7 @@ static int IsXAddrMode (Line* L)
static int NoXAddrMode (Line* L)
static int NoXAddrMode (const Line* L)
/* Return true if the given line does use the X register */
{
return !IsXAddrMode (L);
@@ -599,7 +599,7 @@ static int NoXAddrMode (Line* L)
static int IsYAddrMode (Line* L)
static int IsYAddrMode (const Line* L)
/* Return true if the given line does use the Y register */
{
unsigned Len = strlen (L->Line);
@@ -608,6 +608,18 @@ static int IsYAddrMode (Line* L)
static int Is16BitStore (const Line* L1, const Line* L2)
/* Check if L1 and L2 are a store of ax into a 16 bit location */
{
unsigned Len1 = strlen (L1->Line);
return (strncmp (L1->Line, "\tsta\t", 5) == 0 &&
strncmp (L2->Line, "\tstx\t", 5) == 0 &&
strncmp (L1->Line+5, L2->Line+5, Len1-5) == 0 &&
strcmp (L2->Line+Len1, "+1") == 0);
}
static Line* FindHint (Line* L, const char* Hint)
/* Search for a line with the given hint */
{
@@ -2698,6 +2710,47 @@ static void OptPtrOps (void)
FreeLines (L2 [1], L2 [7]);
}
/* Check for
*
* ldy #$xx
* lda (sp),y
* tax
* dey
* lda (sp),y
* sta yyy
* stx yyy+1
*
* and replace it by
*
* ldy #$xx
* lda (sp),y
* sta yyy+1
* dey
* lda (sp),y
* sta yyy
*
* Provided that X is not used later.
*/
else if (LineMatch (L, "\tldy\t#$") &&
GetNextCodeLines (L, L2, 6) &&
LineFullMatch (L2 [0], "\tlda\t(sp),y") &&
LineFullMatch (L2 [1], "\ttax") &&
LineFullMatch (L2 [2], "\tdey") &&
LineFullMatch (L2 [3], "\tlda\t(sp),y") &&
Is16BitStore (L2[4], L2[5]) &&
!RegXUsed (L2[5])) {
/* Found - replace it */
L2[1] = ReplaceLine (L2[1], L2[5]->Line);
L2[1]->Line[3] = 'a';
/* Delete the remaining lines */
FreeLine (L2[5]);
/* Start over at last line */
L = L2[4];
}
/* Next Line */
L = NextCodeLine (L);
}
@@ -4450,7 +4503,7 @@ void OptDoOpt (void)
/* Ok, now start the real optimizations */
Flags = 1UL;
for (I = 0; I < sizeof(OptFuncs)/sizeof(OptFuncs[0]); ++I) {
for (I = 0; I < sizeof(OptFuncs)/sizeof(OptFuncs[0]); ++I, Flags <<= 1) {
if ((OptDisable & Flags) == 0) {
OptFuncs[I] ();
} else if (Verbose || Debug) {