]> git.sur5r.net Git - cc65/blob - src/cc65/coptptrstore.h
Another optimization for array stores.
[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  *      lda     #<(label+0)
56  *      ldx     #>(label+0)
57  *      clc
58  *      adc     xxx
59  *      bcc     L
60  *      inx
61  * L:   jsr     pushax
62  *      ldx     #$00
63  *      lda     yyy
64  *      ldy     #$00
65  *      jsr     staspidx
66  *
67  * and replace it by:
68  *
69  *      ldy     xxx
70  *      ldx     #$00
71  *      lda     yyy
72  *      sta     label,y
73  */
74
75 unsigned OptPtrStore2 (CodeSeg* S);
76 /* Search for the sequence:
77  *
78  *      lda     #<(label+0)
79  *      ldx     #>(label+0)
80  *      ldy     aaa
81  *      clc
82  *      adc     (sp),y
83  *      bcc     L
84  *      inx
85  * L:   jsr     pushax
86  *      ldx     #$00
87  *      lda     yyy
88  *      ldy     #$00
89  *      jsr     staspidx
90  *
91  * and replace it by:
92  *
93  *      ldy     aaa
94  *      ldx     #$00
95  *      lda     (sp),y
96  *      tay
97  *      lda     yyy
98  *      sta     label,y
99  */
100
101 unsigned OptPtrStore3 (CodeSeg* S);
102 /* Search for the sequence:
103  *
104  *      lda     #<(label+0)
105  *      ldx     #>(label+0)
106  *      ldy     aaa
107  *      clc
108  *      adc     (sp),y
109  *      bcc     L
110  *      inx
111  * L:   jsr     pushax
112  *      ldy     #bbb
113  *      ldx     #$00
114  *      lda     (sp),y
115  *      ldy     #$00
116  *      jsr     staspidx
117  *
118  * and replace it by:
119  *
120  *      ldy     aaa
121  *      lda     (sp),y
122  *      tax
123  *      ldy     #bbb-2
124  *      lda     (sp),y
125  *      sta     label,x
126  *      ldx     #$00
127  */
128
129 unsigned OptPtrStore4 (CodeSeg* S);
130 /* Search for the sequence:
131  *
132  *      ldy     #offs1
133  *      clc
134  *      adc     (sp),y
135  *      bcc     L
136  *      inx
137  * L:   jsr     pushax
138  *      ldy     #offs2
139  *      ldx     #$00
140  *      lda     (sp),y
141  *      ldy     #$00
142  *      jsr     staspidx
143  *
144  * and replace it by:
145  *
146  *      sta     ptr1
147  *      stx     ptr1+1
148  *      ldx     #$00
149  *      ldy     #offs2-2
150  *      lda     (sp),y
151  *      ldy     #offs1
152  *      sta     (ptr1),y
153  */
154
155 unsigned OptPtrStore5 (CodeSeg* S);
156 /* Search for the sequence:
157  *
158  *      clc
159  *      adc     xxx
160  *      bcc     L
161  *      inx
162  * L:   jsr     pushax
163  *      ldy     yyy
164  *      ldx     #$00
165  *      lda     (sp),y
166  *      ldy     #$00
167  *      jsr     staspidx
168  *
169  * and replace it by:
170  *
171  *      sta     ptr1
172  *      stx     ptr1+1
173  *      ldy     yyy-2
174  *      ldx     #$00
175  *      lda     (sp),y
176  *      ldy     xxx
177  *      sta     (ptr1),y
178  *
179  * In case a/x is loaded from the register bank before the clc, we can even
180  * use the register bank instead of ptr1.
181  */
182                                    
183 unsigned OptPtrStore6 (CodeSeg* S);
184 /* Search for the sequence:
185  *
186  *      jsr     pushax
187  *      ldy     xxx
188  *      jsr     ldauidx
189  *      subop
190  *      ldy     yyy
191  *      jsr     staspidx
192  *
193  * and replace it by:
194  *
195  *      sta     ptr1
196  *      stx     ptr1+1
197  *      ldy     xxx
198  *      ldx     #$00
199  *      lda     (ptr1),y
200  *      subop
201  *      ldy     yyy
202  *      sta     (ptr1),y
203  *
204  * In case a/x is loaded from the register bank before the pushax, we can even
205  * use the register bank instead of ptr1.
206  *
207  */
208
209
210
211 /* End of coptptrstore.h */
212 #endif
213
214
215
216