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).
@ -623,37 +623,68 @@ pat sde
/****************************************/ /****************************************/
pat adi $1==2 pat adi $1==2
with hlreg dereg with hlreg dereg
gen dad de yields hl gen
with dereg hlreg dad de
gen dad de yields hl yields hl
with hlreg hlreg with dereg hlreg
gen dad hl yields hl gen
with dereg dereg dad de
gen xchg. yields hl
dad hl yields hl with hlreg hlreg
gen
dad hl
yields hl
with dereg dereg
gen
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 hl_or_de hl_or_de with const2 hl_or_de
uses areg yields %2 {const2, 0-%1.num}
gen mov a,%2.2 leaving
sub %1.2 adi 2
mov %1.2,a with smallconst2 hl_or_de
mov a,%2.1 yields %2 {smallconst2, 0-%1.num}
sbb %1.1 leaving
mov %1.1,a yields %1 adi 2
with hl_or_de hl_or_de with hl_or_de const2
uses areg uses areg
gen mov a,%2.2 gen
sub %1.2 mvi a, {const1, %2.num & 0xff}
mov %2.2,a sub %1.2
mov a,%2.1 mov %1.2, a
sbb %1.1 mvi a, {const1, %2.num >> 8}
mov %2.1,a yields %2 sbb %1.1
mov %1.1, a
yields %1
with hl_or_de hl_or_de
uses areg
gen
mov a,%2.2
sub %1.2
mov %1.2,a
mov a,%2.1
sbb %1.1
mov %1.1,a
yields %1
with hl_or_de hl_or_de
uses areg
gen
mov a,%2.2
sub %1.2
mov %2.2,a
mov a,%2.1
sbb %1.1
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 == 8) && ($2 == 2) pat loc sli ($1==1) && ($2==2)
with hl_or_de with hlreg
gen move %1.2, %1.1 gen
mvi %1.2, {const1,0} yields %1 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)
with hl_or_de
gen
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
@ -1791,65 +1848,121 @@ with yields {const2,$1}
leaving bne $2 leaving bne $2
pat bra pat bra
with STACK with STACK
gen jmp {label,$1} gen
jmp {label,$1}
pat blt pat blt
with hl_or_de hl_or_de STACK with const2 hl_or_de STACK
uses areg uses areg
gen mov a,%2.2 gen
sub %1.2 mov a, %2.2
mov a,%2.1 sui {const1, %1.num & 0xff}
sbb %1.1 mov a, %2.1
jm {label,$1} sbi {const1, %1.num >> 8}
jm {label, $1}
pat ble with hl_or_de const2 STACK
with hl_or_de hl_or_de STACK uses areg
uses areg gen
gen mov a,%1.2 mvi a, {const1, %2.num & 0xff}
sub %2.2 sub %1.2
mov a,%1.1 mvi a, {const1, %2.num >> 8}
sbb %2.1 sbb %1.1
jp {label,$1} jm {label, $1}
with hl_or_de hl_or_de STACK
pat beq uses areg
with hl_or_de hl_or_de STACK gen
uses areg mov a,%2.2
gen mov a,%2.2 sub %1.2
cmp %1.2 mov a,%2.1
jnz {label,1f} sbb %1.1
mov a,%2.1 jm {label,$1}
cmp %1.1
jz {label,$1}
1:
pat bne
with hl_or_de hl_or_de STACK
uses areg
gen mov a,%2.2
cmp %1.2
jnz {label,$1}
mov a,%2.1
cmp %1.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 pat bgt
with hl_or_de hl_or_de STACK leaving
uses areg exg 2
gen mov a,%1.2 blt $1
sub %2.2
mov a,%1.1 pat bge
sbb %2.1 with const2 hl_or_de STACK
jm {label,$1} 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
uses areg
gen
mov a,%2.2
sub %1.2
mov a,%2.1
sbb %1.1
jp {label,$1}
pat ble
leaving
exg 2
bge $1
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
uses areg
gen
mov a,%2.2
cmp %1.2
jnz {label,1f}
mov a,%2.1
cmp %1.1
jz {label,$1}
1:
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
uses areg
gen
mov a,%2.2
cmp %1.2
jnz {label,$1}
mov a,%2.1
cmp %1.1
jnz {label,$1}
pat zlt pat zlt
with STACK with STACK
@ -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
sphl. dad sp
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 pat asp $1==0 /* do nothing */
with STACK
gen dcx sp
dcx sp
pat asp $1==0 /* do nothing */ pat asp ($1>0) && ($1<12)
with STACK
pat asp $1==2 uses hlreg
with exact src1or2 gen
with STACK pop hl
gen inx sp leaving
inx sp asp $1-2
pat asp $1==4
with exact src1or2 leaving asp 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 ;
%%; %%;