-
Notifications
You must be signed in to change notification settings - Fork 0
/
special-gbz80.def
163 lines (144 loc) · 2.47 KB
/
special-gbz80.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// these rules are from peep-gbz80.def
replace{
ld hl, #%1
ld a, (hl)
} by {
; gbz80 peephole 0 used ldh instead of ld a, (hl).
ldh a, (#%1)
} if operandsLiteral(%1), immdInRange(0xff00 0xffff '|' %1 0 %2), notUsed('hl')
replace{
ld a, (#%1)
} by {
; gbz80 peephole 0b used ldh instead of ld.
ldh a, (#%1)
} if operandsLiteral(%1), immdInRange(0xff00 0xffff '|' %1 0 %2)
replace{
ld hl, #%1
ld (hl), a
} by {
; gbz80 peephole 1 used ldh instead of ld (hl), a.
ldh (#%1), a
} if operandsLiteral(%1), immdInRange(0xff00 0xffff '|' %1 0 %2), notUsed('hl')
replace{
ld (#%1), a
} by {
; gbz80 peephole 1b used ldh instead of ld.
ldh (#%1), a
} if operandsLiteral(%1), immdInRange(0xff00 0xffff '|' %1 0 %2)
replace {
ld a, (hl)
inc hl
} by {
ld a, (hl+)
; gbz80 peephole 2 used ldi to increment hl after load
}
replace {
ld %1, (hl)
inc hl
} by {
ld a, (hl+)
ld %1, a
; gbz80 peephole 2b used ldi to increment hl after load
} if notUsed('a')
replace {
ld %1, (hl)
dec hl
} by {
ld a, (hl-)
ld %1, a
; gbz80 peephole 3 used ldd to decrement hl after load
} if notUsed('a')
replace {
ld a, (hl)
dec hl
} by {
ld a, (hl-)
; gbz80 peephole 3b used ldd to decrement hl after load
}
replace {
ld (hl), a
inc hl
} by {
ld (hl+), a
; gbz80 peephole 4 used ldi to increment hl after load
}
replace {
ld (hl), %1
inc hl
} by {
ld a, %1
ld (hl+), a
; gbz80 peephole 4b used ldi to increment hl after load
} if notUsed('a')
replace {
ld (hl), a
dec hl
} by {
ld (hl-), a
; gbz80 peephole 5 used ldd to decrement hl after load
}
replace {
ld (hl), %1
dec hl
} by {
ld a, %1
ld (hl-), a
; gbz80 peephole 5b used ldd to decrement hl after load
} if notUsed('a')
replace {
inc hl
dec hl
} by {
; gbz80 peephole 6 removed inc hl / dec hl pair
}
replace {
ld (hl), a
inc de
ld a, (de)
inc hl
} by {
ld (hl+), a
; gbz80 peephole 7 used ldi to increment hl
inc de
ld a, (de)
}
replace {
ld a, (hl)
ld (bc), a
inc bc
inc hl
} by {
ld a, (hl+)
; gbz80 peephole 8 used ldi to increment hl
ld (bc), a
inc bc
}
replace restart {
ldhl sp,#%1
dec hl
} by {
; gbz80 peephole 7 combined ld and dec.
ldhl sp,#%2
} if immdInRange(-128 127 '-' %1 1 %2)
replace {
pop %1
pop %2
push %2
push %1
} by {
; gbz80 peephole 8 removed not needed push
pop %1
pop %2
} if notSame(%1 %2), notUsed('sp')
replace {
pop %1
pop %2
push %2
push %1
} by {
; gbz80 peephole 8b removed not needed push
ldhl sp, #0
pop %1
pop %2
ld sp, hl
} if notSame(%1 %2), notUsed('hl')