]> git.sur5r.net Git - cc65/blob - src/cc65/coptptrstore.h
Be more flexible when detecting a special sequence that can be optimized.
[cc65] / src / cc65 / coptptrstore.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                               coptptrstore.h                              */
4 /*                                                                           */
5 /*                      Optimize stores through pointers                     */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2012,      Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef COPTPTRSTORE_H
37 #define COPTPTRSTORE_H
38
39
40
41 /* cc65 */
42 #include "codeseg.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Code                                    */
48 /*****************************************************************************/
49
50
51
52 unsigned OptPtrStore1 (CodeSeg* S);
53 /* Search for the sequence:
54  *
55  *      clc
56  *      adc     xxx
57  *      bcc     L
58  *      inx
59  * L:   jsr     pushax
60  *      ldx     #$00
61  *      lda     yyy
62  *      ldy     #$00
63  *      jsr     staspidx
64  *
65  * and replace it by:
66  *
67  *      sta     ptr1
68  *      stx     ptr1+1
69  *      ldy     xxx
70  *      ldx     #$00
71  *      lda     yyy
72  *      sta     (ptr1),y
73  *
74  * or by
75  *
76  *      ldy     xxx
77  *      ldx     #$00
78  *      lda     yyy
79  *      sta     label,y
80  *
81  * or by
82  *
83  *      ldy     xxx
84  *      ldx     #$00
85  *      lda     yyy
86  *      sta     $xxxx,y
87  *
88  * or by
89  *
90  *      ldy     xxx
91  *      ldx     #$00
92  *      lda     yyy
93  *      sta     (zp),y
94  *
95  * depending on the two instructions preceeding the sequence above.
96  */                                
97
98 unsigned OptPtrStore2 (CodeSeg* S);
99 /* Search for the sequence:
100  *
101  *      lda     #<(label+0)
102  *      ldx     #>(label+0)
103  *      ldy     aaa
104  *      clc
105  *      adc     (sp),y
106  *      bcc     L
107  *      inx
108  * L:   jsr     pushax
109  *      ldx     #$00
110  *      lda     yyy
111  *      ldy     #$00
112  *      jsr     staspidx
113  *
114  * and replace it by:
115  *
116  *      ldy     aaa
117  *      ldx     #$00
118  *      lda     (sp),y
119  *      tay
120  *      lda     yyy
121  *      sta     label,y
122  */
123
124 unsigned OptPtrStore3 (CodeSeg* S);
125 /* Search for the sequence:
126  *
127  *      lda     #<(label+0)
128  *      ldx     #>(label+0)
129  *      ldy     aaa
130  *      clc
131  *      adc     (sp),y
132  *      bcc     L
133  *      inx
134  * L:   jsr     pushax
135  *      ldy     #bbb
136  *      ldx     #$00
137  *      lda     (sp),y
138  *      ldy     #$00
139  *      jsr     staspidx
140  *
141  * and replace it by:
142  *
143  *      ldy     aaa
144  *      lda     (sp),y
145  *      tax
146  *      ldy     #bbb-2
147  *      lda     (sp),y
148  *      sta     label,x
149  *      ldx     #$00
150  */
151
152 unsigned OptPtrStore4 (CodeSeg* S);
153 /* Search for the sequence:
154  *
155  *      clc
156  *      adc     xxx
157  *      bcc     L
158  *      inx
159  * L:   jsr     pushax
160  *      ldy     yyy
161  *      ldx     #$00
162  *      lda     (sp),y
163  *      ldy     #$00
164  *      jsr     staspidx
165  *
166  * and replace it by:
167  *
168  *      sta     ptr1
169  *      stx     ptr1+1
170  *      ldy     yyy-2
171  *      ldx     #$00
172  *      lda     (sp),y
173  *      ldy     xxx
174  *      sta     (ptr1),y
175  *
176  * In case a/x is loaded from the register bank before the clc, we can even
177  * use the register bank instead of ptr1.
178  */
179
180 unsigned OptPtrStore5 (CodeSeg* S);
181 /* Search for the sequence:
182  *
183  *      jsr     pushax
184  *      ldy     xxx
185  *      jsr     ldauidx
186  *      subop
187  *      ldy     yyy
188  *      jsr     staspidx
189  *
190  * and replace it by:
191  *
192  *      sta     ptr1
193  *      stx     ptr1+1
194  *      ldy     xxx
195  *      ldx     #$00
196  *      lda     (ptr1),y
197  *      subop
198  *      ldy     yyy
199  *      sta     (ptr1),y
200  *
201  * In case a/x is loaded from the register bank before the pushax, we can even
202  * use the register bank instead of ptr1.
203  *
204  */
205
206
207
208 /* End of coptptrstore.h */
209 #endif
210
211
212
213