]> git.sur5r.net Git - cc65/blob - src/cc65/coptshift.h
fixed optimization bug where array index is 16-bit, e.g. arr16[i & 0x7f7f]
[cc65] / src / cc65 / coptshift.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                coptshift.h                                */
4 /*                                                                           */
5 /*                              Optimize shifts                              */
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 COPTSHIFT_H
37 #define COPTSHIFT_H
38
39
40
41 /* cc65 */
42 #include "codeseg.h"
43
44
45
46 /*****************************************************************************/
47 /*                              Optimize shifts                              */
48 /*****************************************************************************/
49
50
51
52 unsigned OptShift1 (CodeSeg* S);
53 /* A call to the shlaxN routine may get replaced by one or more asl insns
54 ** if the value of X is not used later. If X is used later, but it is zero
55 ** on entry and it's a shift by one, it may get replaced by:
56 **
57 **      asl     a
58 **      bcc     L1
59 **      inx
60 **  L1:
61 */
62
63 unsigned OptShift2 (CodeSeg* S);
64 /* The sequence
65 **
66 **      bpl     L
67 **      dex
68 ** L:   jsr     asraxN
69 **
70 ** might be replaced by N copies of
71 **
72 **      cmp     #$80
73 **      ror     a
74 **
75 ** if X is not used later (X is assumed to be zero on entry).
76 */
77
78 unsigned OptShift3 (CodeSeg* S);
79 /* The sequence
80 **
81 **      bcc     L
82 **      inx
83 ** L:   jsr     shrax1
84 **
85 ** may get replaced by
86 **
87 **      ror     a
88 **
89 ** if X is zero on entry and unused later. For shift counts > 1, more
90 **
91 **      shr     a
92 **
93 ** must be added.
94 */
95
96 unsigned OptShift4 (CodeSeg* S);
97 /* Calls to the asraxN or shraxN routines may get replaced by one or more lsr
98 ** insns if the value of X is zero.
99 */
100
101 unsigned OptShift5 (CodeSeg* S);
102 /* Search for the sequence
103 **
104 **      lda     xxx
105 **      ldx     yyy
106 **      jsr     aslax1/asrax1/shlax1/shrax1
107 **      sta     aaa
108 **      stx     bbb
109 **
110 ** and replace it by
111 **
112 **      lda     xxx
113 **      asl     a
114 **      sta     aaa
115 **      lda     yyy
116 **      rol     a
117 **      sta     bbb
118 **
119 ** or similar, provided that a/x is not used later
120 */
121
122 unsigned OptShift6 (CodeSeg* S);
123 /* Inline the shift subroutines. */
124
125
126
127 /* End of coptshift.h */
128
129 #endif