static OptFunc DOptPtrLoad8 = { OptPtrLoad8, "OptPtrLoad8", 108, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrLoad9 = { OptPtrLoad9, "OptPtrLoad9", 86, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrLoad10 = { OptPtrLoad10, "OptPtrLoad10", 100, 0, 0, 0, 0, 0 };
+static OptFunc DOptPtrLoad11 = { OptPtrLoad11, "OptPtrLoad11", 190, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrStore1 = { OptPtrStore1, "OptPtrStore1", 100, 0, 0, 0, 0, 0 };
static OptFunc DOptPtrStore2 = { OptPtrStore2, "OptPtrStore2", 40, 0, 0, 0, 0, 0 };
static OptFunc DOptPush1 = { OptPush1, "OptPush1", 65, 0, 0, 0, 0, 0 };
&DOptPrecalc,
&DOptPtrLoad1,
&DOptPtrLoad10,
+ &DOptPtrLoad11,
&DOptPtrLoad2,
&DOptPtrLoad3,
&DOptPtrLoad4,
Changes += RunOptFunc (S, &DOptPtrLoad7, 1);
Changes += RunOptFunc (S, &DOptPtrLoad8, 1);
Changes += RunOptFunc (S, &DOptPtrLoad9, 1);
+ Changes += RunOptFunc (S, &DOptPtrLoad10, 1);
+ Changes += RunOptFunc (S, &DOptPtrLoad11, 1);
Changes += RunOptFunc (S, &DOptNegAX1, 1);
Changes += RunOptFunc (S, &DOptNegAX2, 1);
Changes += RunOptFunc (S, &DOptNegAX3, 1);
do {
C = 0;
- C += RunOptFunc (S, &DOptPtrLoad10, 1);
C += RunOptFunc (S, &DOptNegA1, 1);
C += RunOptFunc (S, &DOptNegA2, 1);
C += RunOptFunc (S, &DOptSub1, 1);
*
* stx ptr1+1
* sta ptr1
- * ldy ...
+ * ldy ...
* ldx #$00
* lda (ptr1),y
*
+unsigned OptPtrLoad11 (CodeSeg* S)
+/* Search for the sequence
+ *
+ * ldy ...
+ * jsr ldaxidx
+ *
+ * and replace it by:
+ *
+ * ldy ...
+ * sta ptr1
+ * stx ptr1+1
+ * lda (ptr1),y
+ * tax
+ * dey
+ * lda (ptr1),y
+ *
+ * This step must be executed *after* OptPtrLoad9! While code size increases
+ * by more than 200%, inlining will greatly improve visibility for the
+ * optimizer, so often part of the code gets improved later. So we will mark
+ * the step with less than 200% so it gets executed when -Oi is in effect.
+ */
+{
+ unsigned Changes = 0;
+
+ /* Walk over the entries */
+ unsigned I = 0;
+ while (I < CS_GetEntryCount (S)) {
+
+ CodeEntry* L[2];
+
+ /* Get next entry */
+ L[0] = CS_GetEntry (S, I);
+
+ /* Check for the sequence */
+ if (L[0]->OPC == OP65_LDY &&
+ CS_GetEntries (S, L+1, I+1, 1) &&
+ CE_IsCallTo (L[1], "ldaxidx") &&
+ !CE_HasLabel (L[1])) {
+
+ CodeEntry* X;
+
+ /* Store the high byte */
+ X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
+ CS_InsertEntry (S, X, I+1);
+
+ /* Store the low byte */
+ X = NewCodeEntry (OP65_STX, AM65_ZP, "ptr1+1", 0, L[0]->LI);
+ CS_InsertEntry (S, X, I+2);
+
+ /* lda (ptr1),y */
+ X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[1]->LI);
+ CS_InsertEntry (S, X, I+3);
+
+ /* tax */
+ X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, L[1]->LI);
+ CS_InsertEntry (S, X, I+4);
+
+ /* dey */
+ X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, L[1]->LI);
+ CS_InsertEntry (S, X, I+5);
+
+ /* lda (ptr1),y */
+ X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[1]->LI);
+ CS_InsertEntry (S, X, I+6);
+
+ /* Delete the call to ldaxidx */
+ CS_DelEntry (S, I+7);
+
+ /* Remember, we had changes */
+ ++Changes;
+
+ }
+
+ /* Next entry */
+ ++I;
+
+ }
+
+ /* Return the number of changes made */
+ return Changes;
+}
+
+
+
* ldy xxx
* ldx #$00
* lda label,y
- */
+ */
unsigned OptPtrLoad4 (CodeSeg* S);
/* Search for the sequence:
* This step must be executed *after* OptPtrLoad1!
*/
+unsigned OptPtrLoad11 (CodeSeg* S);
+/* Search for the sequence
+ *
+ * ldy ...
+ * jsr ldaxidx
+ *
+ * and replace it by:
+ *
+ * ldy ...
+ * sta ptr1
+ * stx ptr1+1
+ * lda (ptr1),y
+ * tax
+ * dey
+ * lda (ptr1),y
+ *
+ * This step must be executed *after* OptPtrLoad9! While code size increases
+ * by more than 200%, inlining will greatly improve visibility for the
+ * optimizer, so often part of the code gets improved later. So we will mark
+ * the step with less than 200% so it gets executed when -Oi is in effect.
+ */
+
/* End of coptptrload.h */