Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#619 from boriel/feature/optimize_cons…
Browse files Browse the repository at this point in the history
…tants_more

feat: add opt54 optimizer recipe
  • Loading branch information
boriel committed Oct 2, 2022
2 parents 5b4321f + f54066a commit 6859d68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/arch/z80/peephole/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"IS_REG16": lambda x: x.strip().lower() in ("af", "bc", "de", "hl", "ix", "iy"),
"IS_REG8": lambda x: x.strip().lower() in ("a", "b", "c", "d", "e", "h", "l", "ixh", "ixl", "iyh", "iyl"),
"IS_LABEL": lambda x: x.strip()[-1:] == ":",
"IS_IMMED": lambda x: not x.strip().startswith("("),
"LEN": lambda x: str(len(x.split())),
"INSTR": lambda x: x.strip().split()[0],
"HIREG": lambda x: {"af": "a", "bc": "b", "de": "d", "hl": "h", "ix": "ixh", "iy": "iyh"}.get(
Expand Down
24 changes: 24 additions & 0 deletions src/arch/z80/peephole/opts/054_o3_ld_a_N_ld_hl_a.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;; Replaces sequence:
;; ld hl, (_XXXX)
;; ld a, l
;;
;; With:
;; ld a, (_XXXX)

OLEVEL: 3
OFLAG: 54

REPLACE {{
ld a, $1
ld hl, ($2)
ld (hl), a
}}

IF {{
!IS_REQUIRED(a) && IS_IMMED($1)
}}

WITH {{
ld hl, ($2)
ld (hl), $1
}}
5 changes: 2 additions & 3 deletions tests/functional/zx48k/opt3_haplo05.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ _dataSprite:
.core.__MAIN_PROGRAM__:
ld a, 4
ld (31744), a
ld a, 83
ld hl, (_dataSprite)
ld (hl), a
ld (hl), 83
ld de, 11
add hl, de
push hl
Expand Down Expand Up @@ -157,5 +156,5 @@ __MUL8B:
ret ; result = HL
ENDP
pop namespace
#line 91 "opt3_haplo05.bas"
#line 90 "zx48k/opt3_haplo05.bas"
END

0 comments on commit 6859d68

Please sign in to comment.