]> git.sur5r.net Git - cc65/commitdiff
Added some code rewriting (may enable optimizations in a few cases).
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 15 Apr 2006 20:31:43 +0000 (20:31 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 15 Apr 2006 20:31:43 +0000 (20:31 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3727 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/codeopt.c
src/cc65/coptstore.c
src/cc65/coptstore.h

index eef303e592964dca23ee6f6f8a629d101c3948e9..0a5a227cdf468130cf0b9783f601243024f8b03e 100644 (file)
@@ -1865,6 +1865,7 @@ static OptFunc DOptStore1       = { OptStore1,       "OptStore1",        70, 0,
 static OptFunc DOptStore2       = { OptStore2,       "OptStore2",       220, 0, 0, 0, 0, 0 };
 static OptFunc DOptStore3       = { OptStore3,       "OptStore3",       120, 0, 0, 0, 0, 0 };
 static OptFunc DOptStore4       = { OptStore4,       "OptStore4",        50, 0, 0, 0, 0, 0 };
+static OptFunc DOptStore5       = { OptStore5,       "OptStore5",       100, 0, 0, 0, 0, 0 };
 static OptFunc DOptStoreLoad           = { OptStoreLoad,    "OptStoreLoad",      0, 0, 0, 0, 0, 0 };
 static OptFunc DOptSub1                = { OptSub1,         "OptSub1",         100, 0, 0, 0, 0, 0 };
 static OptFunc DOptSub2                = { OptSub2,         "OptSub2",         100, 0, 0, 0, 0, 0 };
@@ -1939,6 +1940,7 @@ static OptFunc* OptFuncs[] = {
     &DOptStore2,
     &DOptStore3,
     &DOptStore4,
+    &DOptStore5,
     &DOptStoreLoad,
     &DOptSub1,
     &DOptSub2,
@@ -2200,6 +2202,7 @@ static unsigned RunOptGroup1 (CodeSeg* S)
     Changes += RunOptFunc (S, &DOptAdd2, 1);
     Changes += RunOptFunc (S, &DOptAdd4, 1);
     Changes += RunOptFunc (S, &DOptStore4, 1);
+    Changes += RunOptFunc (S, &DOptStore5, 1);
     Changes += RunOptFunc (S, &DOptShift1, 1);
     Changes += RunOptFunc (S, &DOptShift2, 1);
     Changes += RunOptFunc (S, &DOptShift3, 1);
@@ -2274,6 +2277,7 @@ static unsigned RunOptGroup3 (CodeSeg* S)
                C += RunOptFunc (S, &DOptDupLoads, 1);
                C += RunOptFunc (S, &DOptStoreLoad, 1);
                C += RunOptFunc (S, &DOptTransfers1, 1);
+               C += RunOptFunc (S, &DOptStore5, 1);
         C += RunOptFunc (S, &DOptPushPop, 1);
         C += RunOptFunc (S, &DOptPrecalc, 1);
 
index b738c38dba02ab924b51f7acae33ee7382f0fc02..d78810cde5cac12c2c47430503f34ebdcd2890ea 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002-2005, Ullrich von Bassewitz                                      */
+/* (C) 2002-2006, Ullrich von Bassewitz                                      */
 /*                Römerstrasse 52                                            */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -386,3 +386,69 @@ unsigned OptStore4 (CodeSeg* S)
 
 
 
+unsigned OptStore5 (CodeSeg* S)
+/* Search for the sequence
+ *
+ *      lda     foo
+ *      ldx     bar
+ *      sta     something
+ *      stx     something-else
+ *
+ * and replace it by
+ *
+ *      lda     foo
+ *      sta     something
+ *      lda     bar
+ *      sta     something-else
+ *
+ * if X is not used later. This replacement doesn't save any cycles or bytes,
+ * but it keeps the value of X, which may be reused later.
+ */
+{
+    unsigned Changes = 0;
+
+    /* Walk over the entries */
+    unsigned I = 0;
+    while (I < CS_GetEntryCount (S)) {
+
+       CodeEntry* L[4];
+
+       /* Get next entry */
+               L[0] = CS_GetEntry (S, I);
+
+        /* Check for the sequence */
+        if (L[0]->OPC == OP65_LDA                           &&
+           !CS_RangeHasLabel (S, I+1, 3)                   &&
+                   CS_GetEntries (S, L+1, I+1, 3)                  &&
+            L[1]->OPC == OP65_LDX                           &&
+            L[2]->OPC == OP65_STA                           &&
+            L[3]->OPC == OP65_STX                           &&
+            !RegXUsed (S, I+4)) {
+
+            CodeEntry* X;
+
+            /* Insert the code after the sequence */
+                   X = NewCodeEntry (OP65_LDA, L[1]->AM, L[1]->Arg, 0, L[1]->LI);
+           CS_InsertEntry (S, X, I+4);
+                   X = NewCodeEntry (OP65_STA, L[3]->AM, L[3]->Arg, 0, L[3]->LI);
+           CS_InsertEntry (S, X, I+5);
+
+                   /* Delete the old code */
+            CS_DelEntry (S, I+3);
+           CS_DelEntry (S, I+1);
+
+           /* Remember, we had changes */
+           ++Changes;
+       }
+
+       /* Next entry */
+       ++I;
+
+    }
+
+    /* Return the number of changes made */
+    return Changes;
+}
+
+
+
index 85042279f56c3b5199ca99182e0179dea81de947..b6ac183538476838e380934a49ee8e203800aaf5 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002-2003 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2002-2006, Ullrich von Bassewitz                                      */
+/*                Römerstrasse 52                                            */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -85,6 +85,25 @@ unsigned OptStore4 (CodeSeg* S);
  * from the load.
  */
 
+unsigned OptStore5 (CodeSeg* S);
+/* Search for the sequence
+ *
+ *      lda     foo
+ *      ldx     bar
+ *      sta     something
+ *      stx     something-else
+ *
+ * and replace it by
+ *
+ *      lda     foo
+ *      sta     something
+ *      lda     bar
+ *      sta     something-else
+ *
+ * if X is not used later. This replacement doesn't save any cycles or bytes,
+ * but it keeps the value of X, which may be reused later.
+ */
+
 
 
 /* End of coptstore.h */