]> git.sur5r.net Git - cc65/blob - src/cc65/coptptrload.h
c2fc76a22cf4bdebdb6e1e853e689e9f2c22ae9d
[cc65] / src / cc65 / coptptrload.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                               coptptrload.h                               */
4 /*                                                                           */
5 /*                      Optimize loads through pointers                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001-2009 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 COPTPTRLOAD_H
37 #define COPTPTRLOAD_H
38
39
40
41 /* cc65 */
42 #include "codeseg.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Code                                    */
48 /*****************************************************************************/
49
50
51
52 unsigned OptPtrLoad1 (CodeSeg* S);
53 /* Search for the sequence:
54  *
55  *      clc
56  *      adc     xxx
57  *      tay
58  *      txa
59  *      adc     yyy
60  *      tax
61  *      tya
62  *      ldy
63  *      jsr     ldauidx
64  *
65  * and replace it by:
66  *
67  *      clc
68  *      adc     xxx
69  *      sta     ptr1
70  *      txa
71  *      adc     yyy
72  *      sta     ptr1+1
73  *      ldy
74  *      ldx     #$00
75  *      lda     (ptr1),y
76  */
77
78 unsigned OptPtrLoad2 (CodeSeg* S);
79 /* Search for the sequence:
80  *
81  *      adc     xxx
82  *      pha
83  *      txa
84  *      iny
85  *      adc     yyy
86  *      tax
87  *      pla
88  *      ldy
89  *      jsr     ldauidx
90  *
91  * and replace it by:
92  *
93  *      adc     xxx
94  *      sta     ptr1
95  *      txa
96  *      iny
97  *      adc     yyy
98  *      sta     ptr1+1
99  *      ldy
100  *      ldx     #$00
101  *      lda     (ptr1),y
102  */
103
104 unsigned OptPtrLoad3 (CodeSeg* S);
105 /* Search for the sequence:
106  *
107  *      lda     #<(label+0)
108  *      ldx     #>(label+0)
109  *      clc
110  *      adc     xxx
111  *      bcc     L
112  *      inx
113  * L:   ldy     #$00
114  *      jsr     ldauidx
115  *
116  * and replace it by:
117  *
118  *      ldy     xxx
119  *      ldx     #$00
120  *      lda     label,y
121  */                               
122
123 unsigned OptPtrLoad4 (CodeSeg* S);
124 /* Search for the sequence:
125  *
126  *      lda     #<(label+0)
127  *      ldx     #>(label+0)
128  *      ldy     #$xx
129  *      clc
130  *      adc     (sp),y
131  *      bcc     L
132  *      inx
133  * L:   ldy     #$00
134  *      jsr     ldauidx
135  *
136  * and replace it by:
137  *
138  *      ldy     #$xx
139  *      lda     (sp),y
140  *      tay
141  *      ldx     #$00
142  *      lda     label,y
143  */
144
145 unsigned OptPtrLoad5 (CodeSeg* S);
146 /* Search for the sequence:
147  *
148  *      clc
149  *      adc     xxx
150  *      bcc     L
151  *      inx
152  * L:   ldy     #$00
153  *      jsr     ldauidx
154  *
155  * and replace it by:
156  *
157  *      ldy     xxx
158  *      sta     ptr1
159  *      stx     ptr1+1
160  *      ldx     #$00
161  *      lda     (ptr1),y
162  */
163
164 unsigned OptPtrLoad6 (CodeSeg* S);
165 /* Search for the sequence:
166  *
167  *      lda     regbank+n
168  *      ldx     regbank+n+1
169  *      sta     regsave
170  *      stx     regsave+1
171  *      clc
172  *      adc     #$01
173  *      bcc     L0005
174  *      inx
175  * L:   sta     regbank+n
176  *      stx     regbank+n+1
177  *      lda     regsave
178  *      ldx     regsave+1
179  *      ldy     #$00
180  *      jsr     ldauidx
181  *
182  * and replace it by:
183  *
184  *      ldy     #$00
185  *      ldx     #$00
186  *      lda     (regbank+n),y
187  *      inc     regbank+n
188  *      bne     L1
189  *      inc     regbank+n+1
190  * L1:  tay                     <- only if flags are used
191  *
192  * This function must execute before OptPtrLoad7!
193  *
194  */
195
196 unsigned OptPtrLoad7 (CodeSeg* S);
197 /* Search for the sequence:
198  *
199  *      lda     zp
200  *      ldx     zp+1
201  *      ldy     xx
202  *      jsr     ldauidx
203  *
204  * and replace it by:
205  *
206  *      ldy     xx
207  *      ldx     #$00
208  *      lda     (zp),y
209  */
210
211 unsigned OptPtrLoad8 (CodeSeg* S);
212 /* Search for the sequence:
213  *
214  *      lda     zp
215  *      ldx     zp+1
216  *      (anything that doesn't change a/x)
217  *      ldy     xx
218  *      jsr     ldauidx
219  *
220  * and replace it by:
221  *
222  *      lda     zp
223  *      ldx     zp+1
224  *      (anything that doesn't change a/x)
225  *      ldy     xx
226  *      ldx     #$00
227  *      lda     (zp),y
228  *
229  * Must execute before OptPtrLoad10!
230  */
231
232 unsigned OptPtrLoad9 (CodeSeg* S);
233 /* Search for the sequence:
234  *
235  *      lda     zp
236  *      ldx     zp+1
237  *      ldy     xx
238  *      jsr     ldaxidx
239  *
240  * and replace it by:
241  *
242  *      ldy     xx
243  *      lda     (zp),y
244  *      tax
245  *      dey
246  *      lda     (zp),y
247  */
248
249 unsigned OptPtrLoad10 (CodeSeg* S);
250 /* Search for the sequence
251  *
252  *      ldy     ...
253  *      jsr     ldauidx
254  *
255  * and replace it by:
256  *
257  *      ldy     ...
258  *      stx     ptr1+1
259  *      sta     ptr1
260  *      ldx     #$00
261  *      lda     (ptr1),y
262  *
263  * This step must be executed *after* OptPtrLoad1!
264  */
265
266
267
268 /* End of coptptrload.h */
269 #endif
270
271
272