]> git.sur5r.net Git - cc65/blob - src/cc65/coptcmp.h
Small but significant shift optimization
[cc65] / src / cc65 / coptcmp.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 coptcmp.h                                 */
4 /*                                                                           */
5 /*                             Optimize compares                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
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  *      stx     xx
69  *      stx     tmp1
70  *      ora     tmp1
71  *
72  * and replace it by
73  *
74  *      stx     xx
75  *      ora     xx
76  */
77
78 unsigned OptCmp2 (CodeSeg* S);
79 /* Search for
80  *
81  *      lda/and/ora/eor ...
82  *      cmp #$00
83  *      jeq/jne
84  * or
85  *      lda/and/ora/eor ...
86  *      cmp #$00
87  *      jsr boolxx
88  *
89  * and remove the cmp.
90  */
91
92 unsigned OptCmp3 (CodeSeg* S);
93 /* Search for
94  *
95  *      lda     x
96  *      ldx     y
97  *      cpx     #a
98  *      bne     L1
99  *      cmp     #b
100  *      jne/jeq L2
101  *
102  * If a is zero, we may remove the compare. If a and b are both zero, we may
103  * replace it by the sequence
104  *
105  *      lda     x
106  *      ora     x+1
107  *      jne/jeq ...
108  *
109  * L1 may be either the label at the branch instruction, or the target label
110  * of this instruction.
111  */
112
113 unsigned OptCmp4 (CodeSeg* S);
114 /* Optimize compares of local variables:
115  *
116  *      ldy     #o
117  *      lda     (sp),y
118  *      tax
119  *      dey
120  *      lda     (sp),y
121  *      cpx     #a
122  *      bne     L1
123  *      cmp     #b
124  *      jne/jeq L2
125  */
126
127 unsigned OptCmp5 (CodeSeg* S);
128 /* Search for calls to compare subroutines followed by a conditional branch
129  * and replace them by cheaper versions, since the branch means that the
130  * boolean value returned by these routines is not needed (we may also check
131  * that explicitly, but for the current code generator it is always true).
132  */
133
134 unsigned OptCmp6 (CodeSeg* S);
135 /* Search for a sequence ldx/txa/branch and remove the txa if A is not
136  * used later.
137  */
138
139 unsigned OptCmp7 (CodeSeg* S);
140 /* Check for register compares where the contents of the register and therefore
141  * the result of the compare is known.
142  */
143
144
145
146 /* End of coptcmp.h */
147
148 #endif
149
150
151