From d63a359a49927342a54104d0730dccc9b67949b5 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 15 Feb 2019 21:30:27 +0100 Subject: [PATCH] Fix nearly all the comparisons, a lot of which were broken. Using a rst for unsigned comparisons is surprisingly not that useful due to marshalling overhead; it's only four bytes to do inline (plus jc), or six for a constant. Also add some useful top optimisations. Star Trek goes from 39890 to 39450 bytes. --- mach/i80/libem/cmps_mag.s | 1 + mach/i80/libem/cmpu_mag.s | 1 - mach/i80/libem/rst.s | 5 +-- mach/i80/ncg/table | 68 +++++++++++++++++++++++++++++++++++++-- mach/i80/top/table | 2 ++ 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/mach/i80/libem/cmps_mag.s b/mach/i80/libem/cmps_mag.s index e6cbaebfb..52a07aa75 100644 --- a/mach/i80/libem/cmps_mag.s +++ b/mach/i80/libem/cmps_mag.s @@ -15,4 +15,5 @@ xra h jp .cmpu_mag ! signs are the same, so an unsigned comparison will do xra h ! set A=H and set the sign flag + ral ! move sign flag into carry ret diff --git a/mach/i80/libem/cmpu_mag.s b/mach/i80/libem/cmpu_mag.s index 9b6ba2b73..633eec78b 100644 --- a/mach/i80/libem/cmpu_mag.s +++ b/mach/i80/libem/cmpu_mag.s @@ -15,5 +15,4 @@ sub l mov a, d sbb h - rar ret diff --git a/mach/i80/libem/rst.s b/mach/i80/libem/rst.s index 714ffbe4e..c018f3f0a 100644 --- a/mach/i80/libem/rst.s +++ b/mach/i80/libem/rst.s @@ -14,7 +14,6 @@ ! ! Also: ! 48 call .cmps_mag -! 25 call .cmpu_mag .define .rst_init .rst_init: @@ -28,8 +27,6 @@ lxi h, .fstoren2 call copy lxi h, .cmps_mag - call copy - lxi h, .cmpu_mag jmp copy ! Copies eight bytes from HL to DE. @@ -39,7 +36,7 @@ copy: mov a, m stax d inx h - inx d + inr e dcr c jnz .1 ret \ No newline at end of file diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index aa2b37070..388394500 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -1618,6 +1618,70 @@ leaving cal ".cmf4" asp 8 lfr 2 pat cmf $1==8 leaving cal ".cmf8" asp 16 lfr 2 +pat cmu zlt $1==2 + with regpair regpair STACK + uses areg + gen + mov a, %2.2 + sub %1.2 + mov a, %2.1 + sbb %1.1 + jc {label, $2} + with const2 regpair STACK + uses areg + gen + mov a, %2.2 + sbi {const1, %1.num & 0xff} + mov a, %2.1 + sbi {const1, %1.num >> 8} + jc {label, $2} + with regpair const2 STACK + uses areg + gen + mvi a, {const1, %2.num & 0xff} + sub %1.2 + mvi a, {const1, %2.num >> 8} + sbb %1.1 + jc {label, $2} + +pat cmu zgt $1==2 + leaving + exg 2 + cmu 2 + zlt $2 + +pat cmu zge $1==2 + with regpair regpair STACK + uses areg + gen + mov a, %2.2 + sub %1.2 + mov a, %2.1 + sbb %1.1 + jnc {label, $2} + with const2 regpair STACK + uses areg + gen + mov a, %2.2 + sbi {const1, %1.num & 0xff} + mov a, %2.1 + sbi {const1, %1.num >> 8} + jnc {label, $2} + with regpair const2 STACK + uses areg + gen + mvi a, {const1, %2.num & 0xff} + sub %1.2 + mvi a, {const1, %2.num >> 8} + sbb %1.1 + jnc {label, $2} + +pat cmu zle $1==2 + leaving + exg 2 + cmu 2 + zge $2 + pat cmu $1==2 with hl_or_de hl_or_de uses areg @@ -1883,7 +1947,7 @@ pat blt #else Call {label, ".cmps_mag"} #endif - jm {label, $1} + jc {label, $1} pat bgt leaving @@ -1899,7 +1963,7 @@ pat bge #else Call {label, ".cmps_mag"} #endif - jp {label, $1} + jnc {label, $1} pat ble leaving diff --git a/mach/i80/top/table b/mach/i80/top/table index c1f8c2156..f03c92d9b 100644 --- a/mach/i80/top/table +++ b/mach/i80/top/table @@ -19,4 +19,6 @@ call X : ret -> jmp X ; push h : lxi h, X : pop d -> lxi d, X : xchg ; push d : lxi d, X : pop h -> lxi h, X : xchg ; +push h : lhld h, X : pop d -> xchg : lhld X ; + %%; -- 2.34.1