X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcoptsize.c;h=9ab398ff6f82dfc63807f6fb062efc8840526a97;hb=c130e597b013e37c94afd6651be1e8859ba7e5ac;hp=f5db1dd6cb46c4a96a0a17a8e99e110e473847ad;hpb=e68b8160ed1a2ff1c154ce0ed9f8539531a09c65;p=cc65 diff --git a/src/cc65/coptsize.c b/src/cc65/coptsize.c index f5db1dd6c..9ab398ff6 100644 --- a/src/cc65/coptsize.c +++ b/src/cc65/coptsize.c @@ -35,10 +35,12 @@ #include +/* common */ +#include "cpu.h" + /* cc65 */ #include "codeent.h" #include "codeinfo.h" -#include "cpu.h" #include "coptsize.h" @@ -64,6 +66,7 @@ struct CallDesc { static const CallDesc CallTable [] = { { "addeqysp", -1, -1, 0, "addeq0sp" }, { "laddeqysp", -1, -1, 0, "laddeq0sp" }, + { "ldaxidx", -1, -1, 1, "ldaxi" }, { "ldaxysp", -1, -1, 1, "ldax0sp" }, { "ldeaxidx", -1, -1, 3, "ldeaxi" }, { "ldeaxysp", -1, -1, 3, "ldeax0sp" }, @@ -81,6 +84,8 @@ static const CallDesc CallTable [] = { { "pushax", -1, 0, -1, "pusha0" }, { "pushax", -1, 0xFF, -1, "pushaFF" }, { "pushaysp", -1, -1, 0, "pusha0sp" }, + { "pushwidx", -1, -1, 1, "pushw" }, + { "pushwysp", -1, -1, 3, "pushw0sp" }, { "staxysp", -1, -1, 0, "stax0sp" }, { "tosaddax", -1, 0, -1, "tosadda0" }, { "tosandax", -1, 0, -1, "tosanda0" }, @@ -90,8 +95,6 @@ static const CallDesc CallTable [] = { { "tosgtax", -1, 0, -1, "tosgta0" }, { "tosleax", -1, 0, -1, "toslea0" }, { "tosorax", -1, 0, -1, "tosora0" }, - { "ldaxidx", -1, -1, 1, "ldaxi" }, - { "ldeaxysp", -1, -1, 3, "ldeax0sp" }, { "lsubeqysp", -1, -1, 0, "lsubeq0sp" }, { "steaxysp", -1, -1, 0, "steax0sp" }, { "subeqysp", -1, -1, 0, "subeq0sp" }, @@ -113,7 +116,6 @@ static const CallDesc CallTable [] = { { "tosumodax", -1, 0, -1, "tosumoda0" }, { "tosumulax", -1, 0, -1, "tosumula0" }, { "tosxorax", -1, 0, -1, "tosxora0" }, - { "zzzzzzzz", -1, -1, -1, "zzzzzzzz" }, #if 0 "tosadd0ax", /* tosaddeax, sreg = 0 */ @@ -156,18 +158,16 @@ static const CallDesc* FindCall (const char* Name) { /* Do a binary search */ int First = 0; - int Last = (sizeof(CallTable) / sizeof(CallTable[0])) - 1; - int Current; - int Result; + int Last = CALL_COUNT - 1; int Found = 0; while (First <= Last) { /* Set current to mid of range */ - Current = (Last + First) / 2; + int Current = (Last + First) / 2; /* Do a compare */ - Result = strcmp (CallTable[Current].LongFunc, Name); + int Result = strcmp (CallTable[Current].LongFunc, Name); if (Result < 0) { First = Current + 1; } else { @@ -179,7 +179,6 @@ static const CallDesc* FindCall (const char* Name) Found = 1; } } - } /* Return the first entry if found, or NULL otherwise */ @@ -211,19 +210,22 @@ unsigned OptSize1 (CodeSeg* S) I = 0; while (I < CS_GetEntryCount (S)) { + const CallDesc* D; + /* Get next entry */ E = CS_GetEntry (S, I); /* Check if it's a subroutine call */ - if (E->OPC == OP65_JSR) { + if (E->OPC == OP65_JSR && (D = FindCall (E->Arg)) != 0) { /* Check for any of the known functions. */ - const CallDesc* D = FindCall (E->Arg); - while (D && strcmp (D->LongFunc, E->Arg) == 0) { + while (1) { + /* Check the registers */ if ((D->A < 0 || D->A == E->RI->In.RegA) && (D->X < 0 || D->X == E->RI->In.RegX) && (D->Y < 0 || D->Y == E->RI->In.RegY)) { + /* Ok, match for all registers */ CodeEntry* X; X = NewCodeEntry (E->OPC, E->AM, D->ShortFunc, 0, E->LI); @@ -232,8 +234,17 @@ unsigned OptSize1 (CodeSeg* S) /* Remember that we had changes */ ++Changes; + + /* Done */ + break; + } + + /* Next table entry, bail out if next entry not valid */ + if (++D >= CallTable + CALL_COUNT || + strcmp (D->LongFunc, E->Arg) != 0) { + /* End of table or entries reached */ + break; } - ++D; } } @@ -267,10 +278,12 @@ unsigned OptSize2 (CodeSeg* S) I = 0; while (I < CS_GetEntryCount (S)) { - /* Get next entry */ CodeEntry* E = CS_GetEntry (S, I); + /* Get the input registers */ + const RegContents* In = &E->RI->In; + /* Assume we have no replacement */ CodeEntry* X = 0; @@ -280,14 +293,14 @@ unsigned OptSize2 (CodeSeg* S) case OP65_LDA: if (CE_KnownImm (E)) { short Val = (short) E->Num; - if (Val == E->RI->In.RegX) { + if (Val == In->RegX) { X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, E->LI); - } else if (Val == E->RI->In.RegY) { + } else if (Val == In->RegY) { X = NewCodeEntry (OP65_TYA, AM65_IMP, 0, 0, E->LI); - } else if (E->RI->In.RegA >= 0 && CPU >= CPU_65C02) { - if (Val == ((E->RI->In.RegA - 1) & 0xFF)) { + } else if (RegValIsKnown (In->RegA) && CPU >= CPU_65C02) { + if (Val == ((In->RegA - 1) & 0xFF)) { X = NewCodeEntry (OP65_DEA, AM65_IMP, 0, 0, E->LI); - } else if (Val == ((E->RI->In.RegA + 1) & 0xFF)) { + } else if (Val == ((In->RegA + 1) & 0xFF)) { X = NewCodeEntry (OP65_INA, AM65_IMP, 0, 0, E->LI); } } @@ -297,11 +310,11 @@ unsigned OptSize2 (CodeSeg* S) case OP65_LDX: if (CE_KnownImm (E)) { short Val = (short) E->Num; - if (E->RI->In.RegX >= 0 && Val == ((E->RI->In.RegX - 1) & 0xFF)) { + if (RegValIsKnown (In->RegX) && Val == ((In->RegX - 1) & 0xFF)) { X = NewCodeEntry (OP65_DEX, AM65_IMP, 0, 0, E->LI); - } else if (E->RI->In.RegX >= 0 && Val == ((E->RI->In.RegX + 1) & 0xFF)) { + } else if (RegValIsKnown (In->RegX) && Val == ((In->RegX + 1) & 0xFF)) { X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, E->LI); - } else if (Val == E->RI->In.RegA) { + } else if (Val == In->RegA) { X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, E->LI); } } @@ -310,11 +323,11 @@ unsigned OptSize2 (CodeSeg* S) case OP65_LDY: if (CE_KnownImm (E)) { short Val = (short) E->Num; - if (E->RI->In.RegY >= 0 && Val == ((E->RI->In.RegY - 1) & 0xFF)) { + if (RegValIsKnown (In->RegY) && Val == ((In->RegY - 1) & 0xFF)) { X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI); - } else if (E->RI->In.RegY >= 0 && Val == ((E->RI->In.RegY + 1) & 0xFF)) { + } else if (RegValIsKnown (In->RegY) && Val == ((In->RegY + 1) & 0xFF)) { X = NewCodeEntry (OP65_INY, AM65_IMP, 0, 0, E->LI); - } else if (Val == E->RI->In.RegA) { + } else if (Val == In->RegA) { X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, E->LI); } }