Kill registers a, de, when i80 ncg does Call libem.

I compiled tests/plat/lib/test.c with ack -mcpm, but i80 ncg did emit
wrong code in writehex(uint32_t) for

    "0123456789abcdef"[code & 0xf]

The code called '.and' to evaluate `code & 0xf`, then tried to call
'.cii' to narrow the result from 4 to 2 bytes, but it passed garbage
instead of 4 to '.cii'.  The rule for '.and' was

    pat and defined($1)
    kills ALL
    uses dereg={const2,$1}
    gen Call {label,".and"}

This failed to kill register de={const2,4}, so ncg pushed de,
expecting to push 4, but actually pushing garbage.

Fix such rules using `mvi a,...` or `lxi de,...` so ncg doesn't track
the token in the register.  This is like the i86 table.  A different
fix would use a dummy instruction `killreg a` or `killreg de` like the
m68020 table.

Also correct 1 to $1 when calling '.exg'.
This commit is contained in:
George Koehler 2017-12-06 22:14:00 -05:00
parent 88207db638
commit 34cf0c8b63

View file

@ -385,8 +385,9 @@ gen dad de
pat loi $1>=512 pat loi $1>=512
kills ALL kills ALL
uses dereg={const2,$1} /* 'uses dereg={const2,$1}' fails to kill de. */
gen Call {label,".loi"} gen lxi de,{const2,$1}
Call {label,".loi"}
pat los $1==2 pat los $1==2
with dereg with dereg
@ -597,8 +598,8 @@ gen 1:
pat sti pat sti
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".sti"} Call {label,".sti"}
pat sts $1==2 pat sts $1==2
with dereg with dereg
@ -702,23 +703,24 @@ gen Call {label,".mli4"}
pat dvi $1==2 pat dvi $1==2
kills ALL kills ALL
uses areg={const1,129} /* 'uses areg={const1,129}' fails to kill a. */
gen Call {label,".dvi2"} yields de gen mvi a,{const1,129}
Call {label,".dvi2"} yields de
pat dvi $1==4 pat dvi $1==4
kills ALL kills ALL
uses areg={const1,129} gen mvi a,{const1,129}
gen Call {label,".dvi4"} Call {label,".dvi4"}
pat rmi $1==2 pat rmi $1==2
kills ALL kills ALL
uses areg={const1,128} gen mvi a,{const1,128}
gen Call {label,".dvi2"} yields de Call {label,".dvi2"} yields de
pat rmi $1==4 pat rmi $1==4
kills ALL kills ALL
uses areg={const1,128} gen mvi a,{const1,128}
gen Call {label,".dvi4"} Call {label,".dvi4"}
pat ngi $1==2 pat ngi $1==2
with hl_or_de with hl_or_de
@ -738,7 +740,7 @@ pat loc sli ($1 == 8) && ($2 == 2)
with hl_or_de with hl_or_de
gen move %1.2, %1.1 gen move %1.2, %1.1
mvi %1.2, {const1,0} yields %1 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
@ -749,13 +751,13 @@ gen Call {label,".sli4"}
pat sri $1==2 pat sri $1==2
kills ALL kills ALL
uses areg={const1,1} gen mvi a,{const1,1}
gen Call {label,".sri2"} yields de Call {label,".sri2"} yields de
pat sri $1==4 pat sri $1==4
kills ALL kills ALL
uses areg={const1,1} gen mvi a,{const1,1}
gen Call {label,".sri4"} Call {label,".sri4"}
/********************************************/ /********************************************/
/* Group 4: Unsigned arithmetic */ /* Group 4: Unsigned arithmetic */
@ -775,23 +777,23 @@ gen Call {label,".mli4"}
pat dvu $1==2 pat dvu $1==2
kills ALL kills ALL
uses areg={const1,1} gen mvi a,{const1,1}
gen Call {label,".dvi2"} yields de Call {label,".dvi2"} yields de
pat dvu $1==4 pat dvu $1==4
kills ALL kills ALL
uses areg={const1,1} gen mvi a,{const1,1}
gen Call {label,".dvi4"} Call {label,".dvi4"}
pat rmu $1==2 pat rmu $1==2
kills ALL kills ALL
uses areg={const1,0} gen mvi a,{const1,0}
gen Call {label,".dvi2"} yields de Call {label,".dvi2"} yields de
pat rmu $1==4 pat rmu $1==4
kills ALL kills ALL
uses areg={const1,0} gen mvi a,{const1,0}
gen Call {label,".dvi4"} Call {label,".dvi4"}
pat slu leaving sli $1 pat slu leaving sli $1
@ -799,16 +801,16 @@ pat loc sru ($1 == 8) && ($2 == 2)
with hl_or_de with hl_or_de
gen move %1.1, %1.2 gen move %1.1, %1.2
mvi %1.1, {const1,0} yields %1 mvi %1.1, {const1,0} yields %1
pat sru $1==2 pat sru $1==2
kills ALL kills ALL
uses areg={const1,0} gen mvi a,{const1,0}
gen Call {label,".sri2"} yields de Call {label,".sri2"} yields de
pat sru $1==4 pat sru $1==4
kills ALL kills ALL
uses areg={const1,0} gen mvi a,{const1,0}
gen Call {label,".sri4"} Call {label,".sri4"}
/********************************************/ /********************************************/
@ -1047,8 +1049,8 @@ with hlreg
pat cii pat cii
kills ALL kills ALL
uses areg={const1,1} gen mvi a,{const1,1}
gen Call {label,".cii"} Call {label,".cii"}
pat loc loc ciu leaving loc $1 loc $2 cuu pat loc loc ciu leaving loc $1 loc $2 cuu
pat loc loc cui leaving loc $1 loc $2 cuu pat loc loc cui leaving loc $1 loc $2 cuu
@ -1081,8 +1083,8 @@ with hl_or_de
pat cuu pat cuu
kills ALL kills ALL
uses areg={const1,0} gen mvi a,{const1,0}
gen Call {label,".cii"} Call {label,".cii"}
pat cfi pat cfi
kills ALL kills ALL
@ -1128,8 +1130,8 @@ gen mov a,%1.2
pat and defined($1) pat and defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".and"} Call {label,".and"}
pat and !defined($1) pat and !defined($1)
with dereg with dereg
@ -1156,8 +1158,8 @@ gen mov a,%1.2
pat ior defined($1) pat ior defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".ior"} Call {label,".ior"}
pat ior !defined($1) pat ior !defined($1)
with dereg with dereg
@ -1184,8 +1186,8 @@ gen mov a,%1.2
pat xor defined($1) pat xor defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".xor"} Call {label,".xor"}
pat xor !defined($1) pat xor !defined($1)
with dereg with dereg
@ -1204,8 +1206,8 @@ gen mov a,%1.2
pat com defined($1) pat com defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".com"} Call {label,".com"}
pat com !defined($1) pat com !defined($1)
with dereg with dereg
@ -1269,8 +1271,8 @@ gen Call {label,".inn2"} yields de
pat inn defined($1) pat inn defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".inn"} yields de Call {label,".inn"} yields de
pat inn !defined($1) pat inn !defined($1)
with dereg with dereg
@ -1284,8 +1286,8 @@ gen Call {label,".set2"} yields de
pat set defined($1) pat set defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".set"} Call {label,".set"}
pat set !defined($1) pat set !defined($1)
with dereg with dereg
@ -1402,8 +1404,8 @@ pat cmi $1==2 leaving sbi 2
pat cmi $1==4 pat cmi $1==4
kills ALL kills ALL
uses areg={const1,1} gen mvi a,{const1,1}
gen Call {label,".cmi4"} yields de Call {label,".cmi4"} yields de
pat cmf $1==4 pat cmf $1==4
kills ALL kills ALL
@ -1412,14 +1414,14 @@ gen Call {label,".cmf4"}
pat cmf $1==8 pat cmf $1==8
kills ALL kills ALL
gen Call {label,".cmf8"} gen Call {label,".cmf8"}
pat cmu $1==2 pat cmu $1==2
with hl_or_de hl_or_de with hl_or_de hl_or_de
uses areg uses areg
gen mov a,%2.1 gen mov a,%2.1
cmp %1.1 cmp %1.1
jz {label,2f} jz {label,2f}
jc {label,1f} jc {label,1f}
0: 0:
lxi %2,{const2,1} lxi %2,{const2,1}
jmp {label,3f} jmp {label,3f}
@ -1436,15 +1438,15 @@ gen mov a,%2.1
pat cmu $1==4 pat cmu $1==4
kills ALL kills ALL
uses areg={const1,0} gen mvi a,{const1,0}
gen Call {label,".cmi4"} yields de Call {label,".cmi4"} yields de
pat cms $1==2 leaving cmi 2 pat cms $1==2 leaving cmi 2
pat cms defined($1) pat cms defined($1)
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".cms"} yields de Call {label,".cms"} yields de
pat cms !defined($1) pat cms !defined($1)
with dereg with dereg
@ -1936,8 +1938,8 @@ gen dad sp
pat blm pat blm
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".blm"} Call {label,".blm"}
pat bls pat bls
with dereg with dereg
@ -1962,8 +1964,8 @@ with src1or2 src1or2 yields %2 %1 %2 %1
pat dup pat dup
kills ALL kills ALL
uses dereg={const2,$1} gen lxi de,{const2,$1}
gen Call {label,".dup"} Call {label,".dup"}
pat dus $1==2 pat dus $1==2
with dereg with dereg
@ -1975,8 +1977,8 @@ with src1or2 src1or2 yields %1 %2
pat exg defined($1) pat exg defined($1)
kills ALL kills ALL
uses dereg={const2,1} gen lxi de,{const2,$1}
gen Call {label,".exg"} Call {label,".exg"}
pat fil pat fil
uses hlreg={label,$1} uses hlreg={label,$1}