From aa6aefdaa0d01b17ae9d86c3cf4b4136a6c72990 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 00:45:09 +0100 Subject: [PATCH 1/3] Add missing header. --- plat/cpm/emu/globals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/plat/cpm/emu/globals.h b/plat/cpm/emu/globals.h index 6979f31aa..92f784188 100644 --- a/plat/cpm/emu/globals.h +++ b/plat/cpm/emu/globals.h @@ -1,6 +1,7 @@ #ifndef GLOBALS_H #define GLOBALS_H +#include #include extern uint8_t ram[0x10000]; From 1564e65c2d760dc95f7f69a80455e1e1f394fe00 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 23:39:15 +0100 Subject: [PATCH 2/3] Add tests for simple comparisons (which i80 fails). --- tests/plat/core/cmi_e.e | 114 ++++++++++++++++++++++++++++++++++++++++ tests/plat/core/cmu_e.e | 111 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 tests/plat/core/cmi_e.e create mode 100644 tests/plat/core/cmu_e.e diff --git a/tests/plat/core/cmi_e.e b/tests/plat/core/cmi_e.e new file mode 100644 index 000000000..43589ee12 --- /dev/null +++ b/tests/plat/core/cmi_e.e @@ -0,0 +1,114 @@ +# + mes 2, EM_WSIZE, EM_PSIZE + + exp $_m_a_i_n + pro $_m_a_i_n, 0 + +mbig + #if EM_WSIZE == 2 + rom 32768 + #else + rom 2147483648 + #endif +mone + rom -1 +zero + rom 0 +one + rom 1 +big + #if EM_WSIZE == 2 + rom 32767 + #else + rom 2147483647 + #endif + + /* 0 < 1 */ + + loe zero + loe one + blt *1 + cmi EM_WSIZE + zlt *1 + + loc __LINE__ + cal $fail + asp EM_WSIZE +1 + + /* 1 > 0 */ + + loe one + loe zero + cmi EM_WSIZE + zgt *2 + + loc __LINE__ + cal $fail + asp EM_WSIZE +2 + + /* 0 <= 0 */ + + loe zero + loe zero + cmi EM_WSIZE + zle *3 + + loc __LINE__ + cal $fail + asp EM_WSIZE +3 + + /* 0 >= 0 */ + + loe zero + loe zero + cmi EM_WSIZE + zge *4 + + loc __LINE__ + cal $fail + asp EM_WSIZE +4 + + /* INT_MIN < 1 */ + + loe mbig + loe one + cmi EM_WSIZE + zlt *5 + + loc __LINE__ + cal $fail + asp EM_WSIZE +5 + + /* 1 > INT_MIN */ + + loe one + loe mbig + cmi EM_WSIZE + zgt *6 + + loc __LINE__ + cal $fail + asp EM_WSIZE +6 + + /* INT_MIN < INT_MAX */ + + loe mbig + loe big + cmi EM_WSIZE + zlt *7 + + loc __LINE__ + cal $fail + asp EM_WSIZE +7 + + cal $finished + end + + diff --git a/tests/plat/core/cmu_e.e b/tests/plat/core/cmu_e.e new file mode 100644 index 000000000..62b83d798 --- /dev/null +++ b/tests/plat/core/cmu_e.e @@ -0,0 +1,111 @@ +# + mes 2, EM_WSIZE, EM_PSIZE + + exp $_m_a_i_n + pro $_m_a_i_n, 0 + +mbig + #if EM_WSIZE == 2 + rom 32768 + #else + rom 2147483648 + #endif +mone + rom -1 +zero + rom 0 +one + rom 1 +big + #if EM_WSIZE == 2 + rom 32767 + #else + rom 2147483647 + #endif + + /* 0 < 1 */ + + loe zero + loe one + cmu EM_WSIZE + zlt *1 + + loc __LINE__ + cal $fail + asp EM_WSIZE +1 + + /* 1 > 0 */ + + loe one + loe zero + cmu EM_WSIZE + zgt *2 + + loc __LINE__ + cal $fail + asp EM_WSIZE +2 + + /* 0 <= 0 */ + + loe zero + loe zero + cmu EM_WSIZE + zle *3 + + loc __LINE__ + cal $fail + asp EM_WSIZE +3 + + /* 0 >= 0 */ + + loe zero + loe zero + cmu EM_WSIZE + zge *4 + + loc __LINE__ + cal $fail + asp EM_WSIZE +4 + + /* INT_MIN > 1 */ + + loe mbig + loe one + cmu EM_WSIZE + zgt *5 + + loc __LINE__ + cal $fail + asp EM_WSIZE +5 + + /* 1 < INT_MIN */ + + loe one + loe mbig + cmu EM_WSIZE + zlt *6 + + loc __LINE__ + cal $fail + asp EM_WSIZE +6 + + /* INT_MIN > INT_MAX */ + + loe mbig + loe big + cmu EM_WSIZE + zgt *7 + + loc __LINE__ + cal $fail + asp EM_WSIZE +7 + + cal $finished + end From f1b128baeb5a8ab1ae1683a395b180d4cb113fb4 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 11 Feb 2019 20:46:06 +0100 Subject: [PATCH 3/3] Signed comparisons now work correctly; sadly, Star Trek increases from 39656 to 39726 bytes. Note that the emulator doesn't set P/V correctly and all the tests fail. Testing in z80ex works fine. --- mach/i80/libem/rst.s | 12 +++++++++++- mach/i80/ncg/table | 18 +++++++++++++++--- mach/i80/top/table | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/mach/i80/libem/rst.s b/mach/i80/libem/rst.s index 7bf6ade29..2e13584e5 100644 --- a/mach/i80/libem/rst.s +++ b/mach/i80/libem/rst.s @@ -17,6 +17,11 @@ shld 0x11 lxi h, rst3 shld 0x19 + + lhld rst4 + shld 0x20 + lhld rst4+2 + shld 0x22 ret ! de = [bc+const1] (remember bc is the frame pointer) @@ -69,4 +74,9 @@ rst3: dad b ret - \ No newline at end of file + + ! Adjust flags for signed comparison +rst4: + rpo + xri 0x80 + ret diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index 00587bcbf..963a1f07f 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -13,6 +13,12 @@ EM_WSIZE = 2 EM_PSIZE = 2 EM_BSIZE = 4 +#ifdef USE_I80_RSTS + #define SIGN_ADJUST rst {const1, 4} +#else + #define SIGN_ADJUST jpo {label, 1f} xri {const1, 0x80} 1: +#endif + SL=4 PROPERTIES @@ -103,7 +109,7 @@ INSTRUCTIONS jnz label:ro cost(3,10). jp label:ro cost(3,10). /* jpe label:ro cost(3,10). */ -/* jpo label:ro cost(3,10). */ + jpo label:ro cost(3,10). jz label:ro cost(3,10). lda label:ro kills a cost(3,13). ldax regind:ro kills a cost(1, 7). @@ -1860,6 +1866,7 @@ pat blt sui {const1, %1.num & 0xff} mov a, %2.1 sbi {const1, %1.num >> 8} + SIGN_ADJUST jm {label, $1} with hl_or_de const2 STACK uses areg @@ -1868,14 +1875,16 @@ pat blt sub %1.2 mvi a, {const1, %2.num >> 8} sbb %1.1 + SIGN_ADJUST jm {label, $1} with hl_or_de hl_or_de STACK uses areg gen - mov a,%2.2 + mov a, %2.2 sub %1.2 - mov a,%2.1 + mov a, %2.1 sbb %1.1 + SIGN_ADJUST jm {label,$1} pat bgt @@ -1891,6 +1900,7 @@ pat bge sui {const1, %1.num & 0xff} mov a, %2.1 sbi {const1, %1.num >> 8} + SIGN_ADJUST jp {label, $1} with hl_or_de const2 STACK uses areg @@ -1899,6 +1909,7 @@ pat bge sub %1.2 mvi a, {const1, %2.num >> 8} sbb %1.1 + SIGN_ADJUST jp {label, $1} with hl_or_de hl_or_de STACK uses areg @@ -1907,6 +1918,7 @@ pat bge sub %1.2 mov a,%2.1 sbb %1.1 + SIGN_ADJUST jp {label,$1} pat ble diff --git a/mach/i80/top/table b/mach/i80/top/table index e77100735..9ff98a330 100644 --- a/mach/i80/top/table +++ b/mach/i80/top/table @@ -1,5 +1,5 @@ -/* 68020 desciptor table for ACK target optimizer */ +/* 8080 desciptor table for ACK target optimizer */ MAXOP 2; @@ -14,5 +14,6 @@ xchg : inx h : xchg -> inx d ; xchg : inx d : xchg -> inx h ; cpi 0 -> ora a ; +call X : ret -> jmp X ; %%;