]> git.sur5r.net Git - cc65/blob - src/cc65/coptcmp.h
Normalized code.
[cc65] / src / cc65 / coptcmp.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 coptcmp.h                                 */
4 /*                                                                           */
5 /*                             Optimize compares                             */
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 COPTCMP_H
37 #define COPTCMP_H
38
39
40
41 /* cc65 */
42 #include "codeseg.h"
43
44
45
46 /*****************************************************************************/
47 /*             Remove calls to the bool transformer subroutines              */
48 /*****************************************************************************/
49
50
51
52 unsigned OptBoolTrans (CodeSeg* S);
53 /* Try to remove the call to boolean transformer routines where the call is
54  * not really needed.
55  */
56
57
58
59 /*****************************************************************************/
60 /*                        Optimizations for compares                         */
61 /*****************************************************************************/
62
63
64
65 unsigned OptCmp1 (CodeSeg* S);
66 /* Search for the sequence
67  *
68  *      ldx     xx
69  *      stx     tmp1
70  *      ora     tmp1
71  *
72  * and replace it by
73  *
74  *      ora     xx
75  */
76
77 unsigned OptCmp2 (CodeSeg* S);
78 /* Search for the sequence
79  *
80  *      stx     xx
81  *      stx     tmp1
82  *      ora     tmp1
83  *
84  * and replace it by
85  *
86  *      stx     xx
87  *      ora     xx
88  */
89
90 unsigned OptCmp3 (CodeSeg* S);
91 /* Search for
92  *
93  *      lda/and/ora/eor ...
94  *      cmp #$00
95  *      jeq/jne
96  * or
97  *      lda/and/ora/eor ...
98  *      cmp #$00
99  *      jsr boolxx
100  *
101  * and remove the cmp.
102  */
103
104 unsigned OptCmp4 (CodeSeg* S);
105 /* Search for
106  *
107  *      lda     x
108  *      ldx     y
109  *      cpx     #a
110  *      bne     L1
111  *      cmp     #b
112  *      jne/jeq L2
113  *
114  * If a is zero, we may remove the compare. If a and b are both zero, we may
115  * replace it by the sequence
116  *
117  *      lda     x
118  *      ora     x+1
119  *      jne/jeq ...
120  *
121  * L1 may be either the label at the branch instruction, or the target label
122  * of this instruction.
123  */
124
125 unsigned OptCmp5 (CodeSeg* S);
126 /* Optimize compares of local variables:
127  *
128  *      ldy     #o
129  *      lda     (sp),y
130  *      tax
131  *      dey
132  *      lda     (sp),y
133  *      cpx     #a
134  *      bne     L1
135  *      cmp     #b
136  *      jne/jeq L2
137  */
138
139 unsigned OptCmp6 (CodeSeg* S);
140 /* Search for calls to compare subroutines followed by a conditional branch
141  * and replace them by cheaper versions, since the branch means that the
142  * boolean value returned by these routines is not needed (we may also check
143  * that explicitly, but for the current code generator it is always true).
144  */
145
146 unsigned OptCmp7 (CodeSeg* S);
147 /* Search for a sequence ldx/txa/branch and remove the txa if A is not
148  * used later.
149  */
150
151 unsigned OptCmp8 (CodeSeg* S);
152 /* Check for register compares where the contents of the register and therefore
153  * the result of the compare is known.
154  */
155
156 unsigned OptCmp9 (CodeSeg* S);
157 /* Search for the sequence
158  *
159  *    sbc       xx
160  *    bvs/bvc   L
161  *    eor       #$80
162  * L: asl       a
163  *    bcc/bcs   somewhere
164  *
165  * If A is not used later (which should be the case), we can branch on the N
166  * flag instead of the carry flag and remove the asl.
167  */
168
169
170
171 /* End of coptcmp.h */
172
173 #endif