Merge pull request #153 from davidgiven/dtrg-i80

i80: more code generator improvements
This commit is contained in:
David Given 2019-02-10 19:45:00 +01:00 committed by GitHub
commit 3991a0db3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 225 additions and 127 deletions

View file

@ -135,7 +135,7 @@ INSTRUCTIONS
rst const1:ro cost(1,11). rst const1:ro cost(1,11).
/* rz cost(1, 8). */ /* rz cost(1, 8). */
sbb reg1:ro kills a:cc cost(1, 4). sbb reg1:ro kills a:cc cost(1, 4).
/* sbi const1:ro kills a:cc cost(2, 7). */ sbi const1:ro kills a:cc cost(2, 7).
shld label:ro cost(3,16). shld label:ro cost(3,16).
sphl cost(1, 5). sphl cost(1, 5).
sta label:ro cost(3,13). sta label:ro cost(3,13).
@ -624,36 +624,67 @@ pat sde
pat adi $1==2 pat adi $1==2
with hlreg dereg with hlreg dereg
gen dad de yields hl gen
dad de
yields hl
with dereg hlreg with dereg hlreg
gen dad de yields hl gen
dad de
yields hl
with hlreg hlreg with hlreg hlreg
gen dad hl yields hl gen
dad hl
yields hl
with dereg dereg with dereg dereg
gen xchg. gen
dad hl yields hl xchg.
dad hl
yields hl
pat adi $1==4 pat adi $1==4
kills ALL kills ALL
gen Call {label,".adi4"} gen
Call {label,".adi4"}
pat sbi $1==2 pat sbi $1==2
with const2 hl_or_de
yields %2 {const2, 0-%1.num}
leaving
adi 2
with smallconst2 hl_or_de
yields %2 {smallconst2, 0-%1.num}
leaving
adi 2
with hl_or_de const2
uses areg
gen
mvi a, {const1, %2.num & 0xff}
sub %1.2
mov %1.2, a
mvi a, {const1, %2.num >> 8}
sbb %1.1
mov %1.1, a
yields %1
with hl_or_de hl_or_de with hl_or_de hl_or_de
uses areg uses areg
gen mov a,%2.2 gen
mov a,%2.2
sub %1.2 sub %1.2
mov %1.2,a mov %1.2,a
mov a,%2.1 mov a,%2.1
sbb %1.1 sbb %1.1
mov %1.1,a yields %1 mov %1.1,a
yields %1
with hl_or_de hl_or_de with hl_or_de hl_or_de
uses areg uses areg
gen mov a,%2.2 gen
mov a,%2.2
sub %1.2 sub %1.2
mov %2.2,a mov %2.2,a
mov a,%2.1 mov a,%2.1
sbb %1.1 sbb %1.1
mov %2.1,a yields %2 mov %2.1,a
yields %2
pat sbi $1==4 pat sbi $1==4
kills ALL kills ALL
@ -702,14 +733,33 @@ pat ngi $1==4
kills ALL kills ALL
gen Call {label,".ngi4"} gen Call {label,".ngi4"}
pat loc sli ($1==1) && ($2==2)
with hlreg
gen
dad hl
yields hl
pat loc sli ($1>=2) && ($1<=7) && ($2==2)
with hlreg
gen
dad hl
yields hl
leaving
loc $1-1
sli 2
pat loc sli ($1==8) && ($2==2) pat loc sli ($1==8) && ($2==2)
with hl_or_de with hl_or_de
gen move %1.2, %1.1 gen
mvi %1.2, {const1,0} yields %1 mov %1.1, %1.2
mvi %1.2, {const1, 0}
yields %1
pat sli $1==2 pat sli $1==2
kills ALL kills ALL
gen Call {label,".sli2"} yields de gen
Call {label,".sli2"}
yields de
pat sli $1==4 pat sli $1==4
kills ALL kills ALL
@ -761,7 +811,14 @@ kills ALL
gen mvi a,{const1,0} gen mvi a,{const1,0}
Call {label,".dvi4"} Call {label,".dvi4"}
pat slu leaving sli $1 pat loc slu ($2==2)
leaving
loc $1
sli $2
pat slu
leaving
sli $1
pat loc sru ($1 == 8) && ($2 == 2) pat loc sru ($1 == 8) && ($2 == 2)
with hl_or_de with hl_or_de
@ -1792,30 +1849,90 @@ with yields {const2,$1}
pat bra pat bra
with STACK with STACK
gen jmp {label,$1} gen
jmp {label,$1}
pat blt pat blt
with const2 hl_or_de STACK
uses areg
gen
mov a, %2.2
sui {const1, %1.num & 0xff}
mov a, %2.1
sbi {const1, %1.num >> 8}
jm {label, $1}
with hl_or_de const2 STACK
uses areg
gen
mvi a, {const1, %2.num & 0xff}
sub %1.2
mvi a, {const1, %2.num >> 8}
sbb %1.1
jm {label, $1}
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK
uses areg uses areg
gen mov a,%2.2 gen
mov a,%2.2
sub %1.2 sub %1.2
mov a,%2.1 mov a,%2.1
sbb %1.1 sbb %1.1
jm {label,$1} jm {label,$1}
pat ble pat bgt
leaving
exg 2
blt $1
pat bge
with const2 hl_or_de STACK
uses areg
gen
mov a, %2.2
sui {const1, %1.num & 0xff}
mov a, %2.1
sbi {const1, %1.num >> 8}
jp {label, $1}
with hl_or_de const2 STACK
uses areg
gen
mvi a, {const1, %2.num & 0xff}
sub %1.2
mvi a, {const1, %2.num >> 8}
sbb %1.1
jp {label, $1}
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK
uses areg uses areg
gen mov a,%1.2 gen
sub %2.2 mov a,%2.2
mov a,%1.1 sub %1.2
sbb %2.1 mov a,%2.1
sbb %1.1
jp {label,$1} jp {label,$1}
pat ble
leaving
exg 2
bge $1
pat beq pat beq
with const2 hl_or_de STACK
uses areg
gen
mov a, %2.2
cpi {const1, %1.num & 0xff}
jnz {label, 1f}
mov a, %2.1
cpi {const1, %1.num >> 8}
jz {label, $1}
1:
with hl_or_de const2 STACK
leaving
exg 2
beq $1
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK
uses areg uses areg
gen mov a,%2.2 gen
mov a,%2.2
cmp %1.2 cmp %1.2
jnz {label,1f} jnz {label,1f}
mov a,%2.1 mov a,%2.1
@ -1824,33 +1941,29 @@ gen mov a,%2.2
1: 1:
pat bne pat bne
with const2 hl_or_de STACK
uses areg
gen
mov a, %2.2
cpi {const1, %1.num & 0xff}
jnz {label, $1}
mov a, %2.1
cpi {const1, %1.num >> 8}
jnz {label, $1}
with hl_or_de const2 STACK
leaving
exg 2
beq $1
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK
uses areg uses areg
gen mov a,%2.2 gen
mov a,%2.2
cmp %1.2 cmp %1.2
jnz {label,$1} jnz {label,$1}
mov a,%2.1 mov a,%2.1
cmp %1.1 cmp %1.1
jnz {label,$1} jnz {label,$1}
pat bge
with hl_or_de hl_or_de STACK
uses areg
gen mov a,%2.2
sub %1.2
mov a,%2.1
sbb %1.1
jp {label,$1}
pat bgt
with hl_or_de hl_or_de STACK
uses areg
gen mov a,%1.2
sub %2.2
mov a,%1.1
sbb %2.1
jm {label,$1}
pat zlt pat zlt
with STACK with STACK
gen pop psw gen pop psw
@ -2027,46 +2140,29 @@ gen 1:
/* Group 15: Miscellaneous */ /* Group 15: Miscellaneous */
/******************************************/ /******************************************/
pat asp $1<=0-6 pat asp ($1<=0-12) || ($1>=12)
with STACK with STACK
uses hlreg={const2,$1} uses hlreg={const2,$1}
gen dad sp gen
dad sp
sphl. sphl.
pat asp $1==0-4 pat asp ($1<0) && ($1>0-12)
with STACK with STACK
gen dcx sp gen
dcx sp push hl
dcx sp leaving
dcx sp asp $1+2
pat asp $1==0-2
with STACK
gen dcx sp
dcx sp
pat asp $1==0 /* do nothing */ pat asp $1==0 /* do nothing */
pat asp $1==2 pat asp ($1>0) && ($1<12)
with exact src1or2
with STACK with STACK
gen inx sp uses hlreg
inx sp gen
pop hl
pat asp $1==4 leaving
with exact src1or2 leaving asp 2 asp $1-2
with STACK
gen inx sp
inx sp
inx sp
inx sp
pat asp $1>=6
with exact src1or2 leaving asp $1-2
with STACK
uses hlreg={const2,$1}
gen dad sp
sphl.
pat ass $1==2 pat ass $1==2
with hlreg STACK with hlreg STACK

View file

@ -13,4 +13,6 @@ mvi X, Y : mov X, Z -> mov X, Z ;
xchg : inx h : xchg -> inx d ; xchg : inx h : xchg -> inx d ;
xchg : inx d : xchg -> inx h ; xchg : inx d : xchg -> inx h ;
cpi 0 -> ora a ;
%%; %%;