Skip to content

Commit 21d3506

Browse files
authored
Merge pull request #396 from boriel/feature/improved_optimizations
Feature/improved optimizations
2 parents 4249bd6 + b919952 commit 21d3506

File tree

8 files changed

+180
-2
lines changed

8 files changed

+180
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;; Replaces sequence:
2+
;; or|xor|and a
3+
;; sbc a, a
4+
;; with
5+
;; xor a
6+
7+
OLEVEL: 1
8+
OFLAG: 14
9+
10+
REPLACE {{
11+
$1 a
12+
sbc a, a
13+
}}
14+
15+
IF {{
16+
($1 IN (or, and, xor))
17+
}}
18+
19+
WITH {{
20+
xor a
21+
}}
22+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
;; Removes sequence
2+
;; ld a, XXXX
3+
;; if a is not used later
4+
5+
OLEVEL: 3
6+
OFLAG: 15
7+
8+
REPLACE {{
9+
ld a, $1
10+
}}
11+
12+
IF {{
13+
!IS_REQUIRED(a)
14+
}}
15+
16+
WITH {{
17+
}}
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;; Replaces sequence:
2+
;; or|xor|and a
3+
;; sbc a, a
4+
;; with
5+
;; xor a
6+
7+
OLEVEL: 1
8+
OFLAG: 17
9+
10+
REPLACE {{
11+
xor a
12+
$1 z, $2
13+
}}
14+
15+
IF {{
16+
($1 IN (jp, jr))
17+
}}
18+
19+
WITH {{
20+
$1 $2
21+
}}
22+

arch/zx48k/peephole/opts/027_ld_h_a_oper_A.opt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ REPLACE {{
1414
}}
1515

1616
IF {{
17-
(($2 == or) || ($2 == xor) || ($2 == and) || ($2 == cp) || ($2 == sub) || ($2 == "add a,") || ($2 == "sbc a,"))
17+
($2 IN (or, xor, and, cp, sub, "add a,", "sbc a,"))
1818
}}
1919

2020
WITH {{

arch/zx48k/peephole/opts/030_ora_jp_nc_jp.opt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ REPLACE {{
1414
}}
1515

1616
IF {{
17-
(($1 == or) || ($1 == and)) && (($2 == jp) || ($2 == jr))
17+
($1 IN (or, xor, and, cp, sub)) && (($2 == jp) || ($2 == jr))
1818
}}
1919

2020
WITH {{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;; Removes useless XOR a
2+
3+
OLEVEL: 3
4+
OFLAG: 103
5+
6+
REPLACE {{
7+
$1 $2
8+
}}
9+
10+
IF {{
11+
($1 IN (and, or)) &&
12+
(($2 == a) || (!IS_REQUIRED(a))) &&
13+
!IS_REQUIRED(f)
14+
}}
15+
16+
WITH {{
17+
}}

tests/functional/ubyteopt.asm

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
jp __MAIN_PROGRAM__
14+
ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
17+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
18+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
19+
ZXBASIC_USER_DATA_END:
20+
__MAIN_PROGRAM__:
21+
ld a, 2
22+
push af
23+
ld a, 1
24+
push af
25+
call _CanDraw
26+
ld hl, 0
27+
ld b, h
28+
ld c, l
29+
__END_PROGRAM:
30+
di
31+
ld hl, (__CALL_BACK__)
32+
ld sp, hl
33+
exx
34+
pop hl
35+
exx
36+
pop iy
37+
pop ix
38+
ei
39+
ret
40+
__CALL_BACK__:
41+
DEFW 0
42+
_CanDraw:
43+
push ix
44+
ld ix, 0
45+
add ix, sp
46+
ld a, (ix+7)
47+
push af
48+
ld h, 0
49+
pop af
50+
cp h
51+
sbc a, a
52+
push af
53+
ld a, (ix+5)
54+
push af
55+
ld h, 0
56+
pop af
57+
cp h
58+
sbc a, a
59+
pop de
60+
or d
61+
push af
62+
ld a, (ix+7)
63+
push af
64+
ld a, 20
65+
pop hl
66+
cp h
67+
sbc a, a
68+
pop de
69+
or d
70+
push af
71+
ld a, (ix+5)
72+
push af
73+
ld a, 31
74+
pop hl
75+
cp h
76+
sbc a, a
77+
pop de
78+
or d
79+
jp z, __LABEL1
80+
xor a
81+
jp _CanDraw__leave
82+
__LABEL1:
83+
ld a, 1
84+
_CanDraw__leave:
85+
ld sp, ix
86+
pop ix
87+
exx
88+
pop hl
89+
pop bc
90+
ex (sp), hl
91+
exx
92+
ret
93+
END

tests/functional/ubyteopt.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function CanDraw(x as ubyte, y as ubyte) as ubyte
2+
if y<0 or x<0 or y>20 or x>31 then return 0
3+
return 1
4+
end function
5+
6+
CanDraw(1, 2)

0 commit comments

Comments
 (0)