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)
@ -271,44 +271,46 @@ pat lol
yields de yields de
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
@ -323,9 +325,11 @@ gen move lb,de
jnz {label,1b} yields de jnz {label,1b} yields 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,85 +482,43 @@ 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
pop de dad de
mov {m},e pop de
inx hl mov {m},e
mov {m},d inx hl
mov {m},d
pat sti $1==1 pat sti $1==1
with label areg with label areg
@ -584,17 +530,20 @@ with hlreg reg
pat sti $1==2 pat sti $1==2
with label hlreg with label hlreg
gen shld %1 gen
with hlreg dereg shld %1
gen mov {m},e with hlreg dereg
inx %1 gen
mov {m},d mov {m},e
with dereg hlreg inx %1
gen xchg. mov {m},d
mov {m},e with dereg hlreg
inx %2 gen
mov {m},d xchg.
mov {m},e
inx %2
mov {m},d
pat sti $1==4 pat sti $1==4
with label hlreg dereg with label hlreg dereg
@ -640,50 +589,34 @@ 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
inx hl
mov {m},d
inx hl
pop de
mov {m},e
inx hl
mov {m},d
pat sde
with hlreg
kills ALL
gen shld {label,$1}
pop hl
shld {label,$1+2}
with hlreg dereg
kills ALL
gen shld {label,$1}
xchg.
shld {label,$1+2}
with dereg hlreg
kills ALL
gen shld {label,$1+2}
xchg.
shld {label,$1}
pat sdf pat sdf
with hl_or_de leaving
kills ALL adp $1
uses hl_or_de={const2,$1} sti 4
gen dad de
pop de pat sde
mov {m},e with hlreg
inx hl kills ALL
mov {m},d gen
inx hl shld {label,$1}
pop de pop hl
mov {m},e shld {label,$1+2}
inx hl with hlreg dereg
mov {m},d kills ALL
gen
shld {label,$1}
xchg.
shld {label,$1+2}
with dereg hlreg
kills ALL
gen
shld {label,$1+2}
xchg.
shld {label,$1}
/****************************************/ /****************************************/
/* Group 3: Integer arithmetic */ /* Group 3: Integer arithmetic */
@ -911,17 +844,33 @@ 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
inr {m} dad lb
jnz {label,1f} inr {m}
inx hl jnz {label,1f}
inr {m} inx hl
1: inr {m}
1:
pat ine pat ine
uses hlreg={label,$1} uses hlreg={label,$1}
@ -935,16 +884,31 @@ 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
mov e,{m} mov e,{m}
inx hl inx hl
mov d,{m} mov d,{m}
dcx de dcx de
mov {m},d mov {m},d
dcx hl dcx hl
mov {m},e mov {m},e
pat dee pat dee
uses hlreg uses hlreg
@ -952,13 +916,26 @@ 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
xra a dad lb
mov {m},a xra a
inx hl mov {m},a
mov {m},a inx hl
mov {m},a
pat zre pat zre
uses hlreg={const2,0} uses hlreg={const2,0}
@ -1200,14 +1177,16 @@ pat and $1==2
yields %1 yields %1
pat and defined($1) pat and defined($1)
kills ALL kills ALL
gen lxi de,{const2,$1} gen
Call {label,".and"} lxi de,{const2,$1}
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,23 +1909,49 @@ 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
mov a,{m} dad lb
inx hl mov a,{m}
ora {m} inx hl
jz {label,$2} ora {m}
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
mov a,{m} dad lb
inx hl mov a,{m}
ora {m} inx hl
jnz {label,$2} ora {m}
jnz {label,$2}
pat ior zeq $1==2 pat ior zeq $1==2
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK