Fix nearly all the comparisons, a lot of which were broken. Using a rst for
authorDavid Given <dg@cowlark.com>
Fri, 15 Feb 2019 20:30:27 +0000 (21:30 +0100)
committerDavid Given <dg@cowlark.com>
Fri, 15 Feb 2019 20:30:27 +0000 (21:30 +0100)
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
mach/i80/libem/cmpu_mag.s
mach/i80/libem/rst.s
mach/i80/ncg/table
mach/i80/top/table

index e6cbaeb..52a07aa 100644 (file)
@@ -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
index 9b6ba2b..633eec7 100644 (file)
@@ -15,5 +15,4 @@
     sub l
     mov a, d
     sbb h
-    rar
     ret
index 714ffbe..c018f3f 100644 (file)
@@ -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
index aa2b370..3883945 100644 (file)
@@ -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
index c1f8c21..f03c92d 100644 (file)
@@ -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 ;
+
 %%;