Add tests for simple and, or, and xor; drastically improve the i80 code

generation for these.
This commit is contained in:
David Given 2019-02-08 22:38:07 +01:00
parent 996188d20a
commit 0ac145a0d1
8 changed files with 524 additions and 146 deletions

View file

@ -46,6 +46,7 @@ TOKENS
const1 = { INT num; } 1 num. const1 = { INT num; } 1 num.
const2 = { INT num; } 2 num. const2 = { INT num; } 2 num.
smallconst2 = { INT num; } 2 num.
label = { ADDR off; } 2 off. label = { ADDR off; } 2 off.
m = { } 2 cost(0,3) "m". m = { } 2 cost(0,3) "m".
@ -54,7 +55,7 @@ SETS
reg1 = reg + lbreg + m. reg1 = reg + lbreg + m.
b_d_h_sp = regpair + stackpointer. b_d_h_sp = regpair + stackpointer.
b_d_h_psw = regpair + psword. b_d_h_psw = regpair + psword.
immediate = const2 + label. immediate = smallconst2 + const2 + label.
src1 = reg. src1 = reg.
src2 = hl_or_de + const2 + label. src2 = hl_or_de + const2 + label.
src1or2 = src1 + src2. src1or2 = src1 + src2.
@ -114,7 +115,7 @@ INSTRUCTIONS
mvi reg1:wo,const1:ro cost(2, 7). mvi reg1:wo,const1:ro cost(2, 7).
/* nop cost(1, 3). */ /* nop cost(1, 3). */
ora reg1:ro kills a:cc cost(1, 4). ora reg1:ro kills a:cc cost(1, 4).
/* ori const1:ro kills a:cc cost(2, 7). */ ori const1:ro kills a:cc cost(2, 7).
/* out const1:ro cost(2,10). */ /* out const1:ro cost(2,10). */
pchl cost(1, 5). pchl cost(1, 5).
pop b_d_h_psw:wo cost(1,10). pop b_d_h_psw:wo cost(1,10).
@ -144,7 +145,7 @@ INSTRUCTIONS
sui const1:ro kills a:cc cost(2, 7). sui const1:ro kills a:cc cost(2, 7).
xchg kills de hl cost(1, 4). xchg kills de hl cost(1, 4).
xra reg1:ro kills a:cc cost(1, 4). xra reg1:ro kills a:cc cost(1, 4).
/* xri const1:ro kills a:cc cost(2, 7). */ xri const1:ro kills a:cc cost(2, 7).
xthl kills hl cost(1,18). xthl kills hl cost(1,18).
@ -225,6 +226,9 @@ gen move %1,%a.2
from hl_or_de yields %1.2 from hl_or_de yields %1.2
from smallconst2
yields {const2, %1.num}
from const2 from const2
uses hl_or_de uses hl_or_de
gen move %1,%a yields %a.2 gen move %1,%a yields %a.2
@ -239,7 +243,12 @@ PATTERNS
/* Group 1: Load instructions */ /* Group 1: Load instructions */
/*********************************************/ /*********************************************/
pat loc yields {const2,$1} pat loc sfit($1, 8)
yields {smallconst2, $1}
pat loc
yields {const2, $1}
pat ldc yields {const2,highw($1)} pat ldc yields {const2,highw($1)}
{const2,loww($1)} {const2,loww($1)}
@ -485,16 +494,17 @@ with hlreg
gen shld {label,$1} gen shld {label,$1}
pat sil pat sil
with dereg with dereg
uses hlreg={const2,$1}, areg uses hlreg={const2,$1}, areg
gen dad lb gen
mov a,{m} dad lb
mov a, {m}
inx hl inx hl
mov h,{m} mov h, {m}
mov l,a mov l, a
mov {m},e mov {m}, e
inx hl inx hl
mov {m},d mov {m}, d
pat sil lil $1==$2 pat sil lil $1==$2
with dereg with dereg
@ -1123,22 +1133,62 @@ leaving loc $1 loc $2 cal ".cfu" asp 4+$1 lfr 4
/*****************************************/ /*****************************************/
pat and $1==2 pat and $1==2
with hl_or_de hl_or_de with hl_or_de smallconst2
uses areg uses areg
gen mov a,%1.2 gen
mov a, %1.2
ani {const1, %2.num & 0xff}
mov %1.2, a
mvi %1.1, {const1, 0}
yields %1
with hl_or_de const2
uses areg
gen
mov a, %1.2
ani {const1, %2.num & 0xff}
mov %1.2, a
mov a, %1.1
ani {const1, %2.num >> 8}
mov %1.1, a
yields %1
with const2 hl_or_de
uses areg
gen
mov a, %2.2
ani {const1, %1.num & 0xff}
mov %2.2, a
mov a, %2.1
ani {const1, %1.num >> 8}
mov %2.1, a
yields %2
with smallconst2 hl_or_de
uses areg
gen
mov a, %2.2
ani {const1, %1.num & 0xff}
mov %2.2, a
mvi %2.1, {const1, 0}
yields %2
with hl_or_de hl_or_de
uses areg
gen
mov a, %1.2
ana %2.2 ana %2.2
mov %2.2,a mov %2.2, a
mov a,%1.1 mov a, %1.1
ana %2.1 ana %2.1
mov %2.1,a yields %2 mov %2.1, a
with hl_or_de hl_or_de yields %2
uses areg with hl_or_de hl_or_de
gen mov a,%1.2 uses areg
gen
mov a,%1.2
ana %2.2 ana %2.2
mov %1.2,a mov %1.2,a
mov a,%1.1 mov a,%1.1
ana %2.1 ana %2.1
mov %1.1,a yields %1 mov %1.1,a
yields %1
pat and defined($1) pat and defined($1)
kills ALL kills ALL
@ -1151,22 +1201,60 @@ kills ALL
gen Call {label,".and"} gen Call {label,".and"}
pat ior $1==2 pat ior $1==2
with hl_or_de hl_or_de with hl_or_de smallconst2
uses areg uses areg
gen mov a,%1.2 gen
mov a, %1.2
ori {const1, %2.num & 0xff}
mov %1.2, a
yields %1
with hl_or_de const2
uses areg
gen
mov a, %1.2
ori {const1, %2.num & 0xff}
mov %1.2, a
mov a, %1.1
ori {const1, %2.num >> 8}
mov %1.1, a
yields %1
with const2 hl_or_de
uses areg
gen
mov a, %2.2
ori {const1, %1.num & 0xff}
mov %2.2, a
mov a, %2.1
ori {const1, %1.num >> 8}
mov %2.1, a
yields %2
with smallconst2 hl_or_de
uses areg
gen
mov a, %2.2
ori {const1, %1.num & 0xff}
mov %2.2, a
yields %2
with hl_or_de hl_or_de
uses areg
gen
mov a, %1.2
ora %2.2 ora %2.2
mov %2.2,a mov %2.2, a
mov a,%1.1 mov a, %1.1
ora %2.1 ora %2.1
mov %2.1,a yields %2 mov %2.1, a
with hl_or_de hl_or_de yields %2
uses areg with hl_or_de hl_or_de
gen mov a,%1.2 uses areg
gen
mov a,%1.2
ora %2.2 ora %2.2
mov %1.2,a mov %1.2,a
mov a,%1.1 mov a,%1.1
ora %2.1 ora %2.1
mov %1.1,a yields %1 mov %1.1,a
yields %1
pat ior defined($1) pat ior defined($1)
kills ALL kills ALL
@ -1179,22 +1267,60 @@ kills ALL
gen Call {label,".ior"} gen Call {label,".ior"}
pat xor $1==2 pat xor $1==2
with hl_or_de hl_or_de with hl_or_de smallconst2
uses areg uses areg
gen mov a,%1.2 gen
mov a, %1.2
xri {const1, %2.num & 0xff}
mov %1.2, a
yields %1
with hl_or_de const2
uses areg
gen
mov a, %1.2
xri {const1, %2.num & 0xff}
mov %1.2, a
mov a, %1.1
xri {const1, %2.num >> 8}
mov %1.1, a
yields %1
with const2 hl_or_de
uses areg
gen
mov a, %2.2
xri {const1, %1.num & 0xff}
mov %2.2, a
mov a, %2.1
xri {const1, %1.num >> 8}
mov %2.1, a
yields %2
with smallconst2 hl_or_de
uses areg
gen
mov a, %2.2
xri {const1, %1.num & 0xff}
mov %2.2, a
yields %2
with hl_or_de hl_or_de
uses areg
gen
mov a, %1.2
xra %2.2 xra %2.2
mov %2.2,a mov %2.2, a
mov a,%1.1 mov a, %1.1
xra %2.1 xra %2.1
mov %2.1,a yields %2 mov %2.1, a
with hl_or_de hl_or_de yields %2
uses areg with hl_or_de hl_or_de
gen mov a,%1.2 uses areg
gen
mov a,%1.2
xra %2.2 xra %2.2
mov %1.2,a mov %1.2,a
mov a,%1.1 mov a,%1.1
xra %2.1 xra %2.1
mov %1.1,a yields %1 mov %1.1,a
yields %1
pat xor defined($1) pat xor defined($1)
kills ALL kills ALL

View file

@ -5,6 +5,7 @@ static char rcsid[] = "$Id$";
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -375,7 +376,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
cp = findcoerc(tp, &machsets[tokexp[i]]); cp = findcoerc(tp, &machsets[tokexp[i]]);
#ifndef NDEBUG #ifndef NDEBUG
if (Debug > 1) if (Debug > 1)
fprintf(stderr, "findcoerc returns 0x%x at position %d\n", (unsigned)cp, i); fprintf(stderr, "findcoerc returns %p at position %d\n", cp, i);
#endif #endif
if (cp == 0) if (cp == 0)
{ {

View file

@ -4,15 +4,18 @@
exp $_m_a_i_n exp $_m_a_i_n
pro $_m_a_i_n, 0 pro $_m_a_i_n, 0
/* And word-sized set */ three
rom 3
one
rom 1
big
rom 256
four /* And var with var */
rom EM_WSIZE
loc 32769 loe three
loc 1 loe one
loe four /* to defeat constant folding */ and EM_WSIZE
and
loc 1 loc 1
cmu EM_WSIZE cmu EM_WSIZE
zeq *1 zeq *1
@ -22,33 +25,61 @@ four
asp 4 asp 4
1 1
/* And triple-word-sized set */ /* And var with const */
four_by_three loe three
rom EM_WSIZE*3 loc 1
and EM_WSIZE
loc 32769
loc 32770
loc 32772
loc 1 loc 1
loc 2
loc 4
loe four_by_three
and
loc 4
cmu EM_WSIZE cmu EM_WSIZE
zne *2 zeq *2
loc 2
cmu EM_WSIZE loc __LINE__
zne *2 cal $fail
asp 4
2
/* And const with var */
loc 3
loe one
and EM_WSIZE
loc 1 loc 1
cmu EM_WSIZE cmu EM_WSIZE
zeq *3 zeq *3
2
loc __LINE__ loc __LINE__
cal $fail cal $fail
asp 4 asp 4
3 3
/* And var with big const */
loe big
loc 257
and EM_WSIZE
loc 256
cmu EM_WSIZE
zeq *4
loc __LINE__
cal $fail
asp 4
4
/* And big const with var */
loc 257
loe big
and EM_WSIZE
loc 256
cmu EM_WSIZE
zeq *5
loc __LINE__
cal $fail
asp 4
5
cal $finished cal $finished
end end

54
tests/plat/core/andv_e.e Normal file
View file

@ -0,0 +1,54 @@
#
mes 2, EM_WSIZE, EM_PSIZE
exp $_m_a_i_n
pro $_m_a_i_n, 0
/* And word-sized set */
four
rom EM_WSIZE
loc 32769
loc 1
loe four /* to defeat constant folding */
and
loc 1
cmu EM_WSIZE
zeq *1
loc __LINE__
cal $fail
asp 4
1
/* And triple-word-sized set */
four_by_three
rom EM_WSIZE*3
loc 32769
loc 32770
loc 32772
loc 1
loc 2
loc 4
loe four_by_three
and
loc 4
cmu EM_WSIZE
zne *2
loc 2
cmu EM_WSIZE
zne *2
loc 1
cmu EM_WSIZE
zeq *3
2
loc __LINE__
cal $fail
asp 4
3
cal $finished
end

View file

@ -4,15 +4,16 @@
exp $_m_a_i_n exp $_m_a_i_n
pro $_m_a_i_n, 0 pro $_m_a_i_n, 0
/* Or word-sized set */ zero
rom 0
one
rom 1
four /* Or var with var */
rom EM_WSIZE
loc 0 loe zero
loc 1 loe one
loe four /* to defeat constant folding */ ior EM_WSIZE
ior
loc 1 loc 1
cmu EM_WSIZE cmu EM_WSIZE
zeq *1 zeq *1
@ -22,33 +23,61 @@ four
asp 4 asp 4
1 1
/* Or triple-word-sized set */ /* Or var with const */
four_by_three loe zero
rom EM_WSIZE*3 loc 1
ior EM_WSIZE
loc 16
loc 32
loc 64
loc 1 loc 1
loc 2
loc 3
loe four_by_three
ior
loc 67
cmu EM_WSIZE cmu EM_WSIZE
zne *2 zeq *2
loc 34
cmu EM_WSIZE loc __LINE__
zne *2 cal $fail
loc 17 asp 4
2
/* Or const with var */
loc 0
loe one
ior EM_WSIZE
loc 1
cmu EM_WSIZE cmu EM_WSIZE
zeq *3 zeq *3
2
loc __LINE__ loc __LINE__
cal $fail cal $fail
asp 4 asp 4
3 3
/* Or var with big const */
loe zero
loc 1000
ior EM_WSIZE
loc 1000
cmu EM_WSIZE
zeq *4
loc __LINE__
cal $fail
asp 4
4
/* Or big const with var */
loc 1000
loe one
ior EM_WSIZE
loc 1001
cmu EM_WSIZE
zeq *5
loc __LINE__
cal $fail
asp 4
5
cal $finished cal $finished
end end

54
tests/plat/core/iorv_e.e Normal file
View file

@ -0,0 +1,54 @@
#
mes 2, EM_WSIZE, EM_PSIZE
exp $_m_a_i_n
pro $_m_a_i_n, 0
/* Or word-sized set */
four
rom EM_WSIZE
loc 0
loc 1
loe four /* to defeat constant folding */
ior
loc 1
cmu EM_WSIZE
zeq *1
loc __LINE__
cal $fail
asp 4
1
/* Or triple-word-sized set */
four_by_three
rom EM_WSIZE*3
loc 16
loc 32
loc 64
loc 1
loc 2
loc 3
loe four_by_three
ior
loc 67
cmu EM_WSIZE
zne *2
loc 34
cmu EM_WSIZE
zne *2
loc 17
cmu EM_WSIZE
zeq *3
2
loc __LINE__
cal $fail
asp 4
3
cal $finished
end

View file

@ -4,16 +4,17 @@
exp $_m_a_i_n exp $_m_a_i_n
pro $_m_a_i_n, 0 pro $_m_a_i_n, 0
/* Xor word-sized set */ three
rom 3
one
rom 1
four /* Xor var with var */
rom EM_WSIZE
loc 32769 loe three
loc 1 loe one
loe four /* to defeat constant folding */ xor EM_WSIZE
xor loc 2
loc 32768
cmu EM_WSIZE cmu EM_WSIZE
zeq *1 zeq *1
@ -22,33 +23,61 @@ four
asp 4 asp 4
1 1
/* Xor triple-word-sized set */ /* Xor var with const */
four_by_three loe three
rom EM_WSIZE*3
loc 32769
loc 32770
loc 32772
loc 1 loc 1
xor EM_WSIZE
loc 2 loc 2
loc 4
loe four_by_three
xor
loc 32768
cmu EM_WSIZE cmu EM_WSIZE
zne *2 zeq *2
loc 32768
cmu EM_WSIZE loc __LINE__
zne *2 cal $fail
loc 32768 asp 4
2
/* Xor const with var */
loc 3
loe one
xor EM_WSIZE
loc 2
cmu EM_WSIZE cmu EM_WSIZE
zeq *3 zeq *3
2
loc __LINE__ loc __LINE__
cal $fail cal $fail
asp 4 asp 4
3 3
/* Xor var with big const */
loe three
loc 1001
xor EM_WSIZE
loc 1002
cmu EM_WSIZE
zeq *4
loc __LINE__
cal $fail
asp 4
4
/* Xor big const with var */
loc 1001
loe three
xor EM_WSIZE
loc 1002
cmu EM_WSIZE
zeq *5
loc __LINE__
cal $fail
asp 4
5
cal $finished cal $finished
end end

54
tests/plat/core/xorv_e.e Normal file
View file

@ -0,0 +1,54 @@
#
mes 2, EM_WSIZE, EM_PSIZE
exp $_m_a_i_n
pro $_m_a_i_n, 0
/* Xor word-sized set */
four
rom EM_WSIZE
loc 32769
loc 1
loe four /* to defeat constant folding */
xor
loc 32768
cmu EM_WSIZE
zeq *1
loc __LINE__
cal $fail
asp 4
1
/* Xor triple-word-sized set */
four_by_three
rom EM_WSIZE*3
loc 32769
loc 32770
loc 32772
loc 1
loc 2
loc 4
loe four_by_three
xor
loc 32768
cmu EM_WSIZE
zne *2
loc 32768
cmu EM_WSIZE
zne *2
loc 32768
cmu EM_WSIZE
zeq *3
2
loc __LINE__
cal $fail
asp 4
3
cal $finished
end