]> git.sur5r.net Git - cc65/blob - src/cc65/coptneg.h
82bd2f39d98f664ff68c3422a6c4123cbd61aea0
[cc65] / src / cc65 / coptneg.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 coptneg.h                                 */
4 /*                                                                           */
5 /*                        Optimize negation sequences                        */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001-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 COPTNEG_H
37 #define COPTNEG_H
38
39
40
41 /* cc65 */
42 #include "codeseg.h"
43
44
45
46 /*****************************************************************************/
47 /*                            bnega optimizations                            */
48 /*****************************************************************************/
49
50
51
52 unsigned OptBNegA1 (CodeSeg* S);
53 /* Check for
54  *
55  *      ldx     #$00
56  *      lda     ..
57  *      jsr     bnega
58  *
59  * Remove the ldx if the lda does not use it.
60  */
61
62 unsigned OptBNegA2 (CodeSeg* S);
63 /* Check for
64  *
65  *      lda     ..
66  *      jsr     bnega
67  *      jeq/jne ..
68  *
69  * Adjust the conditional branch and remove the call to the subroutine.
70  */
71
72
73
74 /*****************************************************************************/
75 /*                            bnegax optimizations                           */
76 /*****************************************************************************/
77
78
79
80 unsigned OptBNegAX1 (CodeSeg* S);
81 /* On a call to bnegax, if X is zero, the result depends only on the value in
82  * A, so change the call to a call to bnega. This will get further optimized
83  * later if possible.
84  */
85
86 unsigned OptBNegAX2 (CodeSeg* S);
87 /* Search for the sequence:
88  *
89  *      lda     (xx),y
90  *      tax
91  *      dey
92  *      lda     (xx),y
93  *      jsr     bnegax
94  *      jne/jeq ...
95  *
96  * and replace it by
97  *
98  *      lda     (xx),y
99  *      dey
100  *      ora     (xx),y
101  *      jeq/jne ...
102  */
103
104 unsigned OptBNegAX3 (CodeSeg* S);
105 /* Search for the sequence:
106  *
107  *      lda     xx
108  *      ldx     yy
109  *      jsr     bnegax
110  *      jne/jeq ...
111  *
112  * and replace it by
113  *
114  *      lda     xx
115  *      ora     xx+1
116  *      jeq/jne ...
117  */
118
119 unsigned OptBNegAX4 (CodeSeg* S);
120 /* Search for the sequence:
121  *
122  *      jsr     xxx
123  *      jsr     bnega(x)
124  *      jeq/jne ...
125  *
126  * and replace it by:
127  *
128  *      jsr     xxx
129  *      <boolean test>
130  *      jne/jeq ...
131  */
132
133
134
135 /*****************************************************************************/
136 /*                            negax optimizations                            */
137 /*****************************************************************************/
138
139
140
141 unsigned OptNegAX1 (CodeSeg* S);
142 /* Search for a call to negax and replace it by
143  *
144  *      eor     #$FF
145  *      clc
146  *      adc     #$01
147  *
148  * if X isn't used later.
149  */
150
151 unsigned OptNegAX2 (CodeSeg* S);
152 /* Search for a call to negax and replace it by
153  *
154  *      ldx     #$FF
155  *      eor     #$FF
156  *      clc
157  *      adc     #$01
158  *      bne     L1
159  *      inx
160  * L1:
161  *
162  * if X is known and zero on entry.
163  */
164
165
166
167 /* End of coptneg.h */
168
169 #endif
170
171
172