]> git.sur5r.net Git - cc65/blob - src/cc65/coptadd.h
Forgot a cast, sorry
[cc65] / src / cc65 / coptadd.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 coptadd.h                                 */
4 /*                                                                           */
5 /*                        Optimize addition sequences                        */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001-2005, 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 COPTADD_H
37 #define COPTADD_H
38
39
40
41 /* cc65 */
42 #include "codeseg.h"
43
44
45
46 /*****************************************************************************/
47 /*                            Optimize additions                             */
48 /*****************************************************************************/
49
50
51
52 unsigned OptAdd1 (CodeSeg* S);
53 /* Search for the sequence
54 **
55 **      jsr     pushax
56 **      ldy     xxx
57 **      ldx     #$00
58 **      lda     (sp),y
59 **      jsr     tosaddax
60 **
61 ** and replace it by:
62 **
63 **      ldy     xxx-2
64 **      clc
65 **      adc     (sp),y
66 **      bcc     L
67 **      inx
68 ** L:
69 */
70
71 unsigned OptAdd2 (CodeSeg* S);
72 /* Search for the sequence
73 **
74 **      ldy     #xx
75 **      lda     (sp),y
76 **      tax
77 **      dey
78 **      lda     (sp),y
79 **      ldy     #$yy
80 **      jsr     addeqysp
81 **
82 ** and replace it by:
83 **
84 **      ldy     #xx-1
85 **      lda     (sp),y
86 **      ldy     #yy
87 **      clc
88 **      adc     (sp),y
89 **      sta     (sp),y
90 **      ldy     #xx
91 **      lda     (sp),y
92 **      ldy     #yy+1
93 **      adc     (sp),y
94 **      sta     (sp),y
95 **
96 ** provided that a/x is not used later.
97 */
98
99 unsigned OptAdd3 (CodeSeg* S);
100 /* Search for the sequence
101 **
102 **      jsr     pushax
103 **      ldx     #$00
104 **      lda     xxx
105 **      jsr     tosaddax
106 **
107 ** and replace it by
108 **
109 **      clc
110 **      adc     xxx
111 **      bcc     L1
112 **      inx
113 ** L1:
114 */
115
116 unsigned OptAdd4 (CodeSeg* S);
117 /* Search for the sequence
118 **
119 **      jsr     pushax
120 **      lda     xxx
121 **      ldx     yyy
122 **      jsr     tosaddax
123 **
124 ** and replace it by
125 **
126 **      clc
127 **      adc     xxx
128 **      pha
129 **      txa
130 **      adc     yyy
131 **      tax
132 **      pla
133 */
134
135 unsigned OptAdd5 (CodeSeg* S);
136 /* Search for a call to incaxn and replace it by an 8 bit add if the X register
137 ** is not used later.
138 */
139
140 unsigned OptAdd6 (CodeSeg* S);
141 /* Search for the sequence
142 **
143 **      adc     ...
144 **      bcc     L
145 **      inx
146 ** L:
147 **
148 ** and remove the handling of the high byte if X is not used later.
149 */
150
151
152
153 /* End of coptadd.h */
154
155 #endif