struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / src / z80 / peeph-r2k.def
blob0cae70296dadb3d6bd55baf4196abec99fe97243
1 // peeph-r2k.def - Rabbit 2000 (derived from Z80 peephole rules)
2 //
3 // Some of these peepholes could be potentially moved to peeph.def, but a
4 // GBZ80 expert should have a look at them before.
5 //
6 // (c) Philipp Klaus Krause (pkk@spth.de, philipp@colecovision.eu) 2006 - 2020
7 // *** modified by Leland Morrison for rabbit 2000 processor 2011
8 //
9 // This program is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 2, or (at your option) any
12 // later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 replace restart {
24 ld iy, #%1
25 ld a, 1 (iy)
26 or a, 0 (iy)
27 } by {
28 ld hl, #%1
29 ld a, (hl)
30 inc hl
31 or a, (hl)
32 ; peephole 65rab used hl instead of iy.
33 } if notUsed('iy'), notUsed('hl')
35 replace restart {
36 ld %1,(hl)
37 or a,%1
38 } by {
39 or a,(hl)
40 ; peephole 68rab used (hl) directly instead of going through %1.
41 } if notUsed(%1), notSame(%1 'a')
43 replace restart {
44 or a,%1
45 or a,a
46 } by {
47 or a,%1
48 ; peephole 73 removed redundant or after or.
51 replace restart {
52 or a,%1 (%2)
53 or a,a
54 } by {
55 or a,%1 (%2)
56 ; peephole 74 removed redundant or after or.
59 replace restart {
60 and a,%1
61 or a,a
62 } by {
63 and a,%1
64 ; peephole 75 removed redundant or after and.
67 replace restart {
68 xor a,%1
69 or a,a
70 } by {
71 xor a,%1
72 ; peephole 76 removed redundant or after xor.
75 replace restart {
76 xor a,%1 (%2)
77 or a,a
78 } by {
79 xor a,%1 (%2)
80 ; peephole 77 removed redundant or after xor.
83 replace restart {
84 sbc hl, %1
85 ld a, h
86 or a, l
87 jp NZ, %2
88 } by {
89 sbc hl, %1
90 jp NZ, %2
91 ; common peephole 102c removed redundant or after sbc.
94 replace restart {
95 sbc hl, %1
96 ld a, h
97 or a, l
98 jp Z, %2
99 } by {
100 sbc hl, %1
101 jp Z, %2
102 ; common peephole 102d removed redundant or after sbc.
105 replace restart {
106 ld %1, %2 (%3)
107 inc %1
108 ld %2 (%3), %1
109 } by {
110 inc %2 (%3)
111 ld %1, %2 (%3)
112 ; peephole 93a incremented in %2 (%3) instead of going through %1.
113 } if notSame(%3 'sp')
115 replace restart {
116 inc hl
117 ld %1,#%2
118 add hl,%1
119 } by {
120 ld %1,#%2+1
121 add hl,%1
122 ; peephole 129rab moved increment of hl to constant.
123 } if notUsed(%1)
125 replace restart {
126 dec hl
127 ld %1,#%2
128 add hl,%1
129 } by {
130 ld %1,#%2-1
131 add hl,%1
132 ; peephole 129rab' moved decrement of hl to constant.
133 } if notUsed(%1)
135 replace restart {
136 inc iy
137 ld %1, %2 (iy)
138 } by {
139 ld %1, %2+1 (iy)
140 ; peephole 129rab'' moved increment of iy to offset.
141 } if notUsed('iy')
143 replace restart {
144 ld %1, a
145 ld a, %2 (%3)
146 adc a, #%4
147 ld %6, %1
148 } by {
149 ld %6, a
150 ld a, %2 (%3)
151 adc a, #%4
152 ; peephole 138rab loaded %6 from a directly instead of going through %1.
153 } if notUsed(%1)
155 replace restart {
156 ld %1, a
157 ld a, %2 (%3)
158 adc a, #%4
159 ld %5, a
160 ld %6, %1
161 } by {
162 ld %6, a
163 ld a, %2 (%3)
164 adc a, #%4
165 ld %5, a
166 ; peephole 138rab' loaded %6 from a directly instead of going through %1.
167 } if notUsed(%1), notSame(%5 %1), notSame(%5 '(hl)' '(de)' '(bc)'), notSame(%5 %6), notSame(%6 '(hl)' '(de)' '(bc)'), notSame(%5 'a'), notSame(%6 'a')
169 replace restart {
170 pop af
171 push hl
172 } by {
173 ; peephole 142rab used 0(sp) to move hl onto the stack.
174 ld 0(sp), hl
175 } if notUsed('a'), notUsed('hl')
177 replace restart {
178 pop af
179 ld hl, #%1
180 push hl
181 } by {
182 ld hl, #%1
183 ; peephole 143rab used 0(sp) to move hl onto the stack.
184 ld 0(sp), hl
185 } if notUsed('a'), notUsed('hl')
187 replace restart {
188 pop af
189 inc sp
190 ld hl,#%1
191 push hl
192 } by {
193 inc sp
194 ld hl,#%1
195 ; peephole 145rab used 0(sp) to move #%1 onto the stack.
196 ld 0(sp), hl
197 } if notUsed('a'), notUsed('hl')
199 replace restart {
200 pop af
201 ld a,#%1
202 push af
203 inc sp
204 } by {
205 ld h,#%1
206 ld 0(sp), hl
207 ; peephole 146rab used 0(sp) to move #%1 onto the stack.
208 inc sp
209 } if notUsed('a'), notUsed('hl')
211 // those are not in z80
212 replace restart {
213 sbc a,%1
214 bit 7,a
215 jp Z,%2
216 } by {
217 sbc a,%1
218 jp P,%2
219 ; peephole 140 used sign flag instead of testing bit 7.
222 replace restart {
223 sbc a,%1
224 bit 7,a
225 jp NZ,%2
226 } by {
227 sbc a,%1
228 jp M,%2
229 ; peephole 141 used sign flag instead of testing bit 7.
232 replace restart {
233 dec %1
234 ld a, %1
235 or a, a
236 } by {
237 dec %1
238 ; peephole 141a removed redundant transfer and flag setting in a
239 } if notUsed('a')