Add rst 3 to get the address of a frame variable; lots of rule overhaulage.

Reduces Star Trek from 41821 to 41055 bytes.
This commit is contained in:
David Given 2019-02-09 13:29:41 +01:00
parent 857f6a6646
commit 10b509d6b6
2 changed files with 247 additions and 224 deletions

View file

@ -10,10 +10,13 @@
mvi a, 0xc3 ! jmp <a16> mvi a, 0xc3 ! jmp <a16>
sta 0x08 sta 0x08
sta 0x10 sta 0x10
sta 0x18
lxi h, rst1 lxi h, rst1
shld 0x09 shld 0x09
lxi h, rst2 lxi h, rst2
shld 0x11 shld 0x11
lxi h, rst3
shld 0x19
ret ret
! de = [bc+const1] (remember bc is the frame pointer) ! de = [bc+const1] (remember bc is the frame pointer)
@ -52,3 +55,18 @@ rst2:
mov m, d mov m, d
ret ret
! hl = bc+const1
rst3:
pop h
mov a, m
inx h
push h
mov l, a
ral
sbb a
mov h, a
dad b
ret

View file

@ -249,8 +249,8 @@ pat loc sfit($1, 8)
pat loc pat loc
yields {const2, $1} yields {const2, $1}
pat ldc yields {const2,highw($1)} pat ldc
{const2,loww($1)} yields {const2, highw($1)} {const2, loww($1)}
#ifdef USE_I80_RSTS #ifdef USE_I80_RSTS
pat lol sfit($1, 8) pat lol sfit($1, 8)
@ -272,43 +272,45 @@ pat lol
pat loe pat loe
uses hlreg uses hlreg
gen lhld {label,$1} yields hl gen
lhld {label,$1}
yields hl
pat lil pat lil
uses hlreg={const2,$1}, dereg leaving
gen dad lb lol $1
mov e,{m} loi 2
inx hl
mov h,{m}
mov l,e
mov e,{m}
inx hl
mov d,{m} yields de
pat lof pat lof
with hl_or_de leaving
kills hl_or_de adp $1
uses hl_or_de={const2,$1} loi 2
gen dad de
mov e,{m} #ifdef USE_I80_RSTS
inx hl pat lal sfit($1, 8)
mov d,{m} yields de uses dereg, hlreg, areg
gen
rst {const1, 3}
data1 {const1, $1}
yields hl
#endif
pat lal pat lal
uses hlreg={const2,$1} uses hlreg={const2,$1}
gen dad lb yields hl gen
dad lb
yields hl
pat lae yields {label,$1} pat lae
yields {label,$1}
pat lxl $1==0 yields lb pat lxl $1==0
yields lb
pat lxl $1==1 pat lxl $1==1
uses dereg, hlreg leaving
gen move {const2,SL},hl lxa 0
dad lb loi 2
mov e,{m}
inx hl
mov d,{m} yields de
pat lxl $1>1 && $1<256 pat lxl $1>1 && $1<256
uses dereg, areg={const1,$1}, hlreg uses dereg, areg={const1,$1}, hlreg
@ -324,8 +326,10 @@ gen move lb,de
pat lxa $1==0 pat lxa $1==0
uses hlreg uses hlreg
gen move {const2,SL},hl gen
dad lb yields hl move {const2,SL},hl
dad lb
yields hl
pat lxa $1==1 pat lxa $1==1
uses dereg, hlreg uses dereg, hlreg
@ -417,17 +421,9 @@ kills ALL
gen Call {label,".loi"} gen Call {label,".loi"}
pat ldl pat ldl
with STACK leaving
uses dereg, hlreg={const2,$1+3} lal $1
gen dad lb loi 4
mov d,{m}
dcx hl
mov e,{m}
dcx hl
push de
mov d,{m}
dcx hl
mov e,{m} yields de
pat lde pat lde
with STACK with STACK
@ -446,17 +442,9 @@ gen lhld {label,$1+2}
lhld {label,$1} yields de hl lhld {label,$1} yields de hl
pat ldf pat ldf
with hl_or_de STACK leaving
uses hl_or_de={const2,$1+3} adp $1
gen dad de loi 4
mov d,{m}
dcx hl
mov e,{m}
dcx hl
push de
mov d,{m}
dcx hl
mov e,{m} yields de
pat lpi pat lpi
uses hl_or_de={label,$1} yields %a uses hl_or_de={label,$1} yields %a
@ -494,81 +482,39 @@ with hlreg
gen shld {label,$1} gen shld {label,$1}
pat sil pat sil
with dereg leaving
uses hlreg={const2,$1}, areg lol $1
gen sti 2
dad lb
mov a, {m}
inx hl
mov h, {m}
mov l, a
mov {m}, e
inx hl
mov {m}, d
pat sil lil $1==$2 pat sil lil $1==$2
with dereg leaving
uses hlreg={const2,$1}, areg dup 2
gen dad lb lol $1
mov a,{m} sti 2
inx hl
mov h,{m}
mov l,a
mov {m},e
inx hl
mov {m},d yields de
pat lil loc adi sil $1==$4 && $3==2
uses hlreg={const2,$1}, dereg, areg
gen dad lb
mov e,{m}
inx hl
mov h,{m}
mov l,e
mov e,{m}
inx hl
mov d,{m}
push hl
lxi hl,{const2,$2}
dad de
xchg.
pop hl
mov {m},d
dcx hl
mov {m},e
pat lil inc sil $1==$3 pat lil inc sil $1==$3
uses hlreg={const2,$1}, areg leaving
gen dad lb lol $1
mov a,{m} dup 2
inx hl loi 2
mov h,{m} inc 2
mov l,a exg 2
inr {m} sti 2
jnz {label,1f}
inx hl
inr {m}
1:
pat lil dec sil $1==$3 pat lil inc sil $1==$3
uses hlreg={const2,$1}, dereg leaving
gen dad lb lol $1
mov e,{m} dup 2
inx hl loi 2
mov h,{m} dec 2
mov l,e exg 2
mov e,{m} sti 2
inx hl
mov d,{m}
dcx de
mov {m},d
dcx hl
mov {m},e
pat stf pat stf
with hl_or_de STACK with hl_or_de STACK
uses hl_or_de={const2,$1} uses hl_or_de={const2,$1}
gen dad de gen
dad de
pop de pop de
mov {m},e mov {m},e
inx hl inx hl
@ -585,13 +531,16 @@ with hlreg reg
pat sti $1==2 pat sti $1==2
with label hlreg with label hlreg
gen shld %1 gen
shld %1
with hlreg dereg with hlreg dereg
gen mov {m},e gen
mov {m},e
inx %1 inx %1
mov {m},d mov {m},d
with dereg hlreg with dereg hlreg
gen xchg. gen
xchg.
mov {m},e mov {m},e
inx %2 inx %2
mov {m},d mov {m},d
@ -640,51 +589,35 @@ kills ALL
gen Call {label,".sti"} gen Call {label,".sti"}
pat sdl pat sdl
with dereg leaving
kills ALL lal $1
uses hlreg={const2,$1} sti 4
gen dad lb
mov {m},e pat sdf
inx hl leaving
mov {m},d adp $1
inx hl sti 4
pop de
mov {m},e
inx hl
mov {m},d
pat sde pat sde
with hlreg with hlreg
kills ALL kills ALL
gen shld {label,$1} gen
shld {label,$1}
pop hl pop hl
shld {label,$1+2} shld {label,$1+2}
with hlreg dereg with hlreg dereg
kills ALL kills ALL
gen shld {label,$1} gen
shld {label,$1}
xchg. xchg.
shld {label,$1+2} shld {label,$1+2}
with dereg hlreg with dereg hlreg
kills ALL kills ALL
gen shld {label,$1+2} gen
shld {label,$1+2}
xchg. xchg.
shld {label,$1} shld {label,$1}
pat sdf
with hl_or_de
kills ALL
uses hl_or_de={const2,$1}
gen dad de
pop de
mov {m},e
inx hl
mov {m},d
inx hl
pop de
mov {m},e
inx hl
mov {m},d
/****************************************/ /****************************************/
/* Group 3: Integer arithmetic */ /* Group 3: Integer arithmetic */
/****************************************/ /****************************************/
@ -912,11 +845,27 @@ pat sbs $1==2 leaving sbi 2
pat inc pat inc
with hl_or_de with hl_or_de
gen inx %1 yields %1 gen
inx %1
yields %1
#ifdef USE_I80_RSTS
pat inl sfit($1, 8)
uses hlreg, areg
gen
rst {const1, 3}
data1 {const1, $1}
inr {m}
jnz {label, 1f}
inx hl
inr {m}
1:
#endif
pat inl pat inl
uses hlreg={const2,$1} uses hlreg={const2,$1}
gen dad lb gen
dad lb
inr {m} inr {m}
jnz {label,1f} jnz {label,1f}
inx hl inx hl
@ -935,6 +884,21 @@ pat dec
with hl_or_de with hl_or_de
gen dcx %1 yields %1 gen dcx %1 yields %1
#ifdef USE_I80_RSTS
pat del sfit($1, 8)
uses hlreg, areg, dereg
gen
rst {const1, 3}
data1 {const1, $1}
mov e, {m}
inx hl
mov d, {m}
dcx de
mov {m}, d
dcx hl
mov {m}, e
#endif
pat del pat del
uses hlreg={const2,$1}, dereg uses hlreg={const2,$1}, dereg
gen dad lb gen dad lb
@ -952,9 +916,22 @@ gen lhld {label,$1}
dcx hl dcx hl
shld {label,$1} shld {label,$1}
#ifdef USE_I80_RSTS
pat zrl sfit($1, 8)
uses hlreg, areg
gen
rst {const1, 3}
data1 {const1, $1}
xra a
mov {m}, a
inx hl
mov {m}, a
#endif
pat zrl pat zrl
uses hlreg={const2,$1}, areg uses hlreg={const2,$1}, areg
gen dad lb gen
dad lb
xra a xra a
mov {m},a mov {m},a
inx hl inx hl
@ -1201,13 +1178,15 @@ pat and $1==2
pat and defined($1) pat and defined($1)
kills ALL kills ALL
gen lxi de,{const2,$1} gen
lxi de,{const2,$1}
Call {label,".and"} Call {label,".and"}
pat and !defined($1) pat and !defined($1)
with dereg with dereg
kills ALL kills ALL
gen Call {label,".and"} gen
Call {label,".and"}
pat ior $1==2 pat ior $1==2
with hl_or_de smallconst2 with hl_or_de smallconst2
@ -1930,19 +1909,45 @@ gen xra a
jnz {label,$1} jnz {label,$1}
1: 1:
#ifdef USE_I80_RSTS
pat lol zeq sfit($1, 8)
uses hlreg, areg
gen
rst {const1, 3}
data1 {const1, $1}
mov a, {m}
inx hl
ora {m}
jz {label, $2}
#endif
pat lol zeq pat lol zeq
with STACK with STACK
uses hlreg={const2,$1}, areg uses hlreg={const2,$1}, areg
gen dad lb gen
dad lb
mov a,{m} mov a,{m}
inx hl inx hl
ora {m} ora {m}
jz {label,$2} jz {label,$2}
#ifdef USE_I80_RSTS
pat lol zne sfit($1, 8)
uses hlreg, areg
gen
rst {const1, 3}
data1 {const1, $1}
mov a, {m}
inx hl
ora {m}
jnz {label, $2}
#endif
pat lol zne pat lol zne
with STACK with STACK
uses hlreg={const2,$1}, areg uses hlreg={const2,$1}, areg
gen dad lb gen
dad lb
mov a,{m} mov a,{m}
inx hl inx hl
ora {m} ora {m}