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
52unsigned 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 (zp),y
80**
81** or by
82**
83** ldy xxx
84** ldx #$00
85** lda yyy
86** sta label,y
87**
88** or by
89**
90** ldy xxx
91** ldx #$00
92** lda yyy
93** sta $xxxx,y
94**
95** depending on the two instructions preceeding the sequence above.
96*/
97
98unsigned OptPtrStore2 (CodeSeg* S);
99/* Search for the sequence:
100**
101** clc
102** adc xxx
103** bcc L
104** inx
105** L: jsr pushax
106** ldy yyy
107** ldx #$00
108** lda (sp),y
109** ldy #$00
110** jsr staspidx
111**
112** and replace it by:
113**
114** sta ptr1
115** stx ptr1+1
116** ldy yyy-2
117** ldx #$00
118** lda (sp),y
119** ldy xxx
120** sta (ptr1),y
121**
122** or by
123**
124** ldy yyy-2
125** ldx #$00
126** lda (sp),y
127** ldy xxx
128** sta (zp),y
129**
130** or by
131**
132** ldy yyy-2
133** ldx #$00
134** lda (sp),y
135** ldy xxx
136** sta label,y
137**
138** or by
139**
140** ldy yyy-2
141** ldx #$00
142** lda (sp),y
143** ldy xxx
144** sta $xxxx,y
145**
146** depending on the code preceeding the sequence above.
147*/
148
149unsigned OptPtrStore3 (CodeSeg* S);
150/* Search for the sequence:
151**
152** jsr pushax
153** ldy xxx
154** jsr ldauidx
155** subop
156** ldy yyy
157** jsr staspidx
158**
159** and replace it by:
160**
161** sta ptr1
162** stx ptr1+1
163** ldy xxx
164** ldx #$00
165** lda (ptr1),y
166** subop
167** ldy yyy
168** sta (ptr1),y
169**
170** In case a/x is loaded from the register bank before the pushax, we can even
171** use the register bank instead of ptr1.
172*/
173
174
175
176/* End of coptptrstore.h */
177
178#endif
179