]> git.sur5r.net Git - cc65/blobdiff - src/cc65/coptsize.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / cc65 / coptsize.c
index 94716a9f06826c064e9f5f84acd9fa002fb27e41..0848bab0ef74da7688a1dcd96d9d8de09fe522b9 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                coptsize.c                                */
+/*                                 coptsize.c                                */
 /*                                                                           */
 /*                              Size optimizations                           */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002-2009, Ullrich von Bassewitz                                      */
+/* (C) 2002-2012, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -83,6 +83,26 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "addeq0sp"
+    },{
+        "laddeq",
+        {
+            /*     A               X               Y             SRegLo   */
+                         1,              0, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "laddeq1"
+    },{
+        "laddeq",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL,              0, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "laddeqa"
     },{
         "laddeqysp",
         {
@@ -133,6 +153,36 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "ldeax0sp"
+    },{
+        "leaaxsp",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL,              0, UNKNOWN_REGVAL, UNKNOWN_REGVAL,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+            UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "leaa0sp"
+    },{
+        "lsubeq",
+        {
+            /*     A               X               Y             SRegLo   */
+                         1,              0, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "lsubeq1"
+    },{
+        "lsubeq",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL,              0, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "lsubeqa"
     },{
         "lsubeqysp",
         {
@@ -283,6 +333,16 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "pusha0sp"
+    },{
+        "pusheax",
+        {
+            /*     A               X               Y             SRegLo   */
+                         0,              0, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "pushl0"
     },{
         "pusheax",
         {
@@ -373,6 +433,16 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "tosanda0"
+    },{
+        "tosandeax",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "tosand0ax"
     },{
         "tosdivax",
         {
@@ -563,6 +633,16 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "tosora0"
+    },{
+        "tosoreax",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "tosor0ax"
     },{
         "tosrsubax",
         {
@@ -573,6 +653,16 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "tosrsuba0"
+    },{
+        "tosrsubeax",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "tosrsub0ax"
     },{
         "tossubax",
         {
@@ -703,29 +793,25 @@ static const CallDesc CallTable [] = {
         },
         F_NONE,
         "tosxora0"
+    },{
+        "tosxoreax",
+        {
+            /*     A               X               Y             SRegLo   */
+            UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL,              0,
+            /*   SRegHi          Ptr1Lo          Ptr1Hi           Tmp1    */
+                         0, UNKNOWN_REGVAL, UNKNOWN_REGVAL, UNKNOWN_REGVAL
+        },
+        F_NONE,
+        "tosxor0ax"
     },
 
-#if 0
-    "laddeqa",           /* laddeq, sreg = 0, x = 0 */
-    "laddeq1",           /* laddeq, sreg = 0, x = 0, a = 1 */
-    "tosand0ax",         /* tosandeax, sreg = 0 */
-    "tosor0ax",          /* tosoreax, sreg = 0 */
-    "tosrsub0ax",        /* tosrsubeax, sreg = 0 */
-    "tosshl0ax",         /* tosshleax, sreg = 0 */
-    "tosasl0ax",         /* tosasleax, sreg = 0 */
-    "tosshr0ax",         /* tosshreax, sreg = 0 */
-    "tosasr0ax",         /* tosasreax, sreg = 0 */
-    "lsubeqa",           /* lsubeq, sreg = 0, x = 0 */
-    "lsubeq1",           /* lsubeq, sreg = 0, x = 0, a = 1 */
-    "tosxor0ax",         /* tosxoreax, sreg = 0 */
-#endif
 };
 #define CALL_COUNT (sizeof(CallTable) / sizeof(CallTable[0]))
 
 
 
 /*****************************************************************************/
-/*                                         Helpers                                  */
+/*                                  Helpers                                  */
 /*****************************************************************************/
 
 
@@ -742,22 +828,22 @@ static const CallDesc* FindCall (const char* Name)
 
     while (First <= Last) {
 
-               /* Set current to mid of range */
-       int Current = (Last + First) / 2;
-
-               /* Do a compare */
-               int Result = strcmp (CallTable[Current].LongFunc, Name);
-       if (Result < 0) {
-           First = Current + 1;
-       } else {
-           Last = Current - 1;
-           if (Result == 0) {
-                       /* Found. Repeat the procedure until the first of all entries
+        /* Set current to mid of range */
+        int Current = (Last + First) / 2;
+
+        /* Do a compare */
+        int Result = strcmp (CallTable[Current].LongFunc, Name);
+        if (Result < 0) {
+            First = Current + 1;
+        } else {
+            Last = Current - 1;
+            if (Result == 0) {
+                /* Found. Repeat the procedure until the first of all entries
                  * with the same name is found.
                  */
-               Found = 1;
-           }
-       }
+                Found = 1;
+            }
+        }
     }
 
     /* Return the first entry if found, or NULL otherwise */
@@ -777,7 +863,7 @@ static int RegMatch (short Expected, short Actual)
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -795,20 +881,17 @@ unsigned OptSize1 (CodeSeg* S)
     /* Are we optimizing for size */
     int OptForSize = (S->CodeSizeFactor < 100);
 
-    /* Generate register info for the following step */
-    CS_GenRegInfo (S);
-
     /* Walk over the entries */
     I = 0;
     while (I < CS_GetEntryCount (S)) {
 
         const CallDesc* D;
 
-       /* Get next entry */
-               E = CS_GetEntry (S, I);
+        /* Get next entry */
+        E = CS_GetEntry (S, I);
 
-       /* Check if it's a subroutine call */
-       if (E->OPC == OP65_JSR && (D = FindCall (E->Arg)) != 0) {
+        /* Check if it's a subroutine call */
+        if (E->OPC == OP65_JSR && (D = FindCall (E->Arg)) != 0) {
 
             /* Get input register info for this insn */
             const RegContents* In = &E->RI->In;
@@ -851,14 +934,11 @@ unsigned OptSize1 (CodeSeg* S)
             }
         }
 
-       /* Next entry */
-       ++I;
+        /* Next entry */
+        ++I;
 
     }
 
-    /* Free register info */
-    CS_FreeRegInfo (S);
-
     /* Return the number of changes made */
     return Changes;
 }
@@ -874,88 +954,82 @@ unsigned OptSize2 (CodeSeg* S)
     unsigned Changes = 0;
     unsigned I;
 
-    /* Generate register info for the following step */
-    CS_GenRegInfo (S);
-
     /* Walk over the entries */
     I = 0;
     while (I < CS_GetEntryCount (S)) {
 
-       /* Get next entry */
-               CodeEntry* E = CS_GetEntry (S, I);
+        /* 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;
-
-       /* Check the instruction */
-       switch (E->OPC) {
-
-           case OP65_LDA:
-               if (CE_IsConstImm (E)) {
-                   short Val = (short) E->Num;
-                   if (Val == In->RegX) {
-                       X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, E->LI);
-                   } else if (Val == In->RegY) {
-                       X = NewCodeEntry (OP65_TYA, AM65_IMP, 0, 0, E->LI);
-                   } else if (RegValIsKnown (In->RegA) && (CPUIsets[CPU] & CPU_ISET_65SC02) != 0) {
-                       if (Val == ((In->RegA - 1) & 0xFF)) {
-                           X = NewCodeEntry (OP65_DEA, AM65_IMP, 0, 0, E->LI);
-                       } else if (Val == ((In->RegA + 1) & 0xFF)) {
-                           X = NewCodeEntry (OP65_INA, AM65_IMP, 0, 0, E->LI);
-                       }
-                   }
-               }
-               break;
-
-           case OP65_LDX:
-               if (CE_IsConstImm (E)) {
-                   short Val = (short) E->Num;
-                   if (RegValIsKnown (In->RegX) && Val == ((In->RegX - 1) & 0xFF)) {
-                       X = NewCodeEntry (OP65_DEX, AM65_IMP, 0, 0, E->LI);
-                           } else if (RegValIsKnown (In->RegX) && Val == ((In->RegX + 1) & 0xFF)) {
-                       X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, E->LI);
-                   } else if (Val == In->RegA) {
-                       X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, E->LI);
+        /* Assume we have no replacement */
+        CodeEntry* X = 0;
+
+        /* Check the instruction */
+        switch (E->OPC) {
+
+            case OP65_LDA:
+                if (CE_IsConstImm (E)) {
+                    short Val = (short) E->Num;
+                    if (Val == In->RegX) {
+                        X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, E->LI);
+                    } else if (Val == In->RegY) {
+                        X = NewCodeEntry (OP65_TYA, AM65_IMP, 0, 0, E->LI);
+                    } else if (RegValIsKnown (In->RegA) && (CPUIsets[CPU] & CPU_ISET_65SC02) != 0) {
+                        if (Val == ((In->RegA - 1) & 0xFF)) {
+                            X = NewCodeEntry (OP65_DEA, AM65_IMP, 0, 0, E->LI);
+                        } else if (Val == ((In->RegA + 1) & 0xFF)) {
+                            X = NewCodeEntry (OP65_INA, AM65_IMP, 0, 0, E->LI);
+                        }
                     }
-               }
-               break;
-
-                   case OP65_LDY:
-               if (CE_IsConstImm (E)) {
-                   short Val = (short) E->Num;
-                   if (RegValIsKnown (In->RegY) && Val == ((In->RegY - 1) & 0xFF)) {
-                       X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI);
-                   } else if (RegValIsKnown (In->RegY) && Val == ((In->RegY + 1) & 0xFF)) {
-                       X = NewCodeEntry (OP65_INY, AM65_IMP, 0, 0, E->LI);
-                   } else if (Val == In->RegA) {
-                       X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, E->LI);
-                   }
-               }
-               break;
-
-           default:
-               /* Avoid gcc warnings */
-               break;
-
-       }
-
-       /* Insert the replacement if we have one */
-       if (X) {
-           CS_InsertEntry (S, X, I+1);
-           CS_DelEntry (S, I);
-           ++Changes;
-       }
-
-       /* Next entry */
-       ++I;
+                }
+                break;
+
+            case OP65_LDX:
+                if (CE_IsConstImm (E)) {
+                    short Val = (short) E->Num;
+                    if (RegValIsKnown (In->RegX) && Val == ((In->RegX - 1) & 0xFF)) {
+                        X = NewCodeEntry (OP65_DEX, AM65_IMP, 0, 0, E->LI);
+                    } else if (RegValIsKnown (In->RegX) && Val == ((In->RegX + 1) & 0xFF)) {
+                        X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, E->LI);
+                    } else if (Val == In->RegA) {
+                        X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, E->LI);
+                    }
+                }
+                break;
+
+            case OP65_LDY:
+                if (CE_IsConstImm (E)) {
+                    short Val = (short) E->Num;
+                    if (RegValIsKnown (In->RegY) && Val == ((In->RegY - 1) & 0xFF)) {
+                        X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI);
+                    } else if (RegValIsKnown (In->RegY) && Val == ((In->RegY + 1) & 0xFF)) {
+                        X = NewCodeEntry (OP65_INY, AM65_IMP, 0, 0, E->LI);
+                    } else if (Val == In->RegA) {
+                        X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, E->LI);
+                    }
+                }
+                break;
 
-    }
+            default:
+                /* Avoid gcc warnings */
+                break;
 
-    /* Free register info */
-    CS_FreeRegInfo (S);
+        }
+
+        /* Insert the replacement if we have one */
+        if (X) {
+            CS_InsertEntry (S, X, I+1);
+            CS_DelEntry (S, I);
+            ++Changes;
+        }
+
+        /* Next entry */
+        ++I;
+
+    }
 
     /* Return the number of changes made */
     return Changes;