Skip to content

Commit 6859d68

Browse files
authored
Merge pull request #619 from boriel/feature/optimize_constants_more
feat: add opt54 optimizer recipe
2 parents 5b4321f + f54066a commit 6859d68

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/arch/z80/peephole/evaluator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"IS_REG16": lambda x: x.strip().lower() in ("af", "bc", "de", "hl", "ix", "iy"),
4141
"IS_REG8": lambda x: x.strip().lower() in ("a", "b", "c", "d", "e", "h", "l", "ixh", "ixl", "iyh", "iyl"),
4242
"IS_LABEL": lambda x: x.strip()[-1:] == ":",
43+
"IS_IMMED": lambda x: not x.strip().startswith("("),
4344
"LEN": lambda x: str(len(x.split())),
4445
"INSTR": lambda x: x.strip().split()[0],
4546
"HIREG": lambda x: {"af": "a", "bc": "b", "de": "d", "hl": "h", "ix": "ixh", "iy": "iyh"}.get(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
;; Replaces sequence:
2+
;; ld hl, (_XXXX)
3+
;; ld a, l
4+
;;
5+
;; With:
6+
;; ld a, (_XXXX)
7+
8+
OLEVEL: 3
9+
OFLAG: 54
10+
11+
REPLACE {{
12+
ld a, $1
13+
ld hl, ($2)
14+
ld (hl), a
15+
}}
16+
17+
IF {{
18+
!IS_REQUIRED(a) && IS_IMMED($1)
19+
}}
20+
21+
WITH {{
22+
ld hl, ($2)
23+
ld (hl), $1
24+
}}

tests/functional/zx48k/opt3_haplo05.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ _dataSprite:
2424
.core.__MAIN_PROGRAM__:
2525
ld a, 4
2626
ld (31744), a
27-
ld a, 83
2827
ld hl, (_dataSprite)
29-
ld (hl), a
28+
ld (hl), 83
3029
ld de, 11
3130
add hl, de
3231
push hl
@@ -157,5 +156,5 @@ __MUL8B:
157156
ret ; result = HL
158157
ENDP
159158
pop namespace
160-
#line 91 "opt3_haplo05.bas"
159+
#line 90 "zx48k/opt3_haplo05.bas"
161160
END

0 commit comments

Comments
 (0)