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