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 };
&DOptStore2,
&DOptStore3,
&DOptStore4,
+ &DOptStore5,
&DOptStoreLoad,
&DOptSub1,
&DOptSub2,
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);
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);
/* */
/* */
/* */
-/* (C) 2002-2005, Ullrich von Bassewitz */
+/* (C) 2002-2006, Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
+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;
+}
+
+
+
/* */
/* */
/* */
-/* (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 */
* 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 */