Use nicely optimised helper tools to do signed comparisons of words. Star Trek
authorDavid Given <dg@cowlark.com>
Thu, 14 Feb 2019 22:57:55 +0000 (23:57 +0100)
committerDavid Given <dg@cowlark.com>
Thu, 14 Feb 2019 22:57:55 +0000 (23:57 +0100)
goes from 40452 to 39890 bytes.

mach/i80/libem/cmps_mag.s [new file with mode: 0644]
mach/i80/libem/cmpu_mag.s [new file with mode: 0644]
mach/i80/ncg/table

diff --git a/mach/i80/libem/cmps_mag.s b/mach/i80/libem/cmps_mag.s
new file mode 100644 (file)
index 0000000..e6cbaeb
--- /dev/null
@@ -0,0 +1,18 @@
+.sect .text
+.sect .rom
+.sect .data
+.sect .bss
+.sect .text
+
+! Does a tristate signed comparison of hl <> de.
+! Returns m flag if hl < de.
+! Returns p flag if hl >= de.
+! This doesn't set z coherently.
+
+.define .cmps_mag
+.cmps_mag:
+    mov a, d
+    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
+    ret
diff --git a/mach/i80/libem/cmpu_mag.s b/mach/i80/libem/cmpu_mag.s
new file mode 100644 (file)
index 0000000..9b6ba2b
--- /dev/null
@@ -0,0 +1,19 @@
+.sect .text
+.sect .rom
+.sect .data
+.sect .bss
+.sect .text
+
+! Does a tristate unsigned comparison of hl <> de.
+! Returns m flag if hl < de.
+! Returns p flag if hl >= de.
+! This doesn't set z coherently.
+
+.define .cmpu_mag
+.cmpu_mag:
+    mov a, e
+    sub l
+    mov a, d
+    sbb h
+    rar
+    ret
index 1cd47d6..0112eba 100644 (file)
@@ -1875,42 +1875,11 @@ pat bra
          jmp {label,$1}
 
 pat blt
-   with const2 hl_or_de STACK
-      uses areg
-      gen
-         mov a, %2.1
-         xri {const1, 0x80}
-         mov %2.1, a
-         mov a, %2.2
-         sui {const1, %1.num & 0xff}
-         mov a, %2.1
-         sbi {const1, (%1.num >> 8) ^ 0x80}
-         jc {label, $1}
-   with hl_or_de const2 STACK
-      uses areg
-      gen
-         mov a, %1.1
-         xri {const1, 0x80}
-         mov %1.1, a
-         mvi a, {const1, %2.num & 0xff}
-         sub %1.2
-         mvi a, {const1, (%2.num >> 8) ^ 0x80}
-         sbb %1.1
-         jc {label, $1}
-   with hl_or_de hl_or_de STACK
+   with hlreg dereg STACK
       uses areg
       gen
-         mov a, %2.1
-         xri {const1, 0x80}
-         mov %2.1, a
-         mov a, %1.1
-         xri {const1, 0x80}
-         mov %1.1, a
-         mov a, %2.2
-         sub %1.2
-         mov a, %2.1
-         sbb %1.1
-         jc {label,$1}
+         Call {label, ".cmps_mag"}
+         jm {label, $1}
 
 pat bgt
    leaving
@@ -1918,42 +1887,11 @@ pat bgt
       blt $1
 
 pat bge
-   with const2 hl_or_de STACK
-      uses areg
-      gen
-         mov a, %2.1
-         xri {const1, 0x80}
-         mov %2.1, a
-         mov a, %2.2
-         sui {const1, %1.num & 0xff}
-         mov a, %2.1
-         sbi {const1, (%1.num >> 8) ^ 0x80}
-         jnc {label, $1}
-   with hl_or_de const2 STACK
-      uses areg
-      gen
-         mov a, %1.1
-         xri {const1, 0x80}
-         mov %1.1, a
-         mvi a, {const1, %2.num & 0xff}
-         sub %1.2
-         mvi a, {const1, (%2.num >> 8) ^ 0x80}
-         sbb %1.1
-         jnc {label, $1}
-   with hl_or_de hl_or_de STACK
+   with hlreg dereg STACK
       uses areg
       gen
-         mov a, %2.1
-         xri {const1, 0x80}
-         mov %2.1, a
-         mov a, %1.1
-         xri {const1, 0x80}
-         mov %1.1, a
-         mov a,%2.2
-         sub %1.2
-         mov a,%2.1
-         sbb %1.1
-         jnc {label,$1}
+         Call {label, ".cmpu_mag"}
+         jp {label, $1}
 
 pat ble
    leaving