From 2924ce8ffae7a9a9e2adacfd015e25d564af3dbe Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 14 Feb 2019 23:57:55 +0100 Subject: [PATCH] Use nicely optimised helper tools to do signed comparisons of words. Star Trek goes from 40452 to 39890 bytes. --- mach/i80/libem/cmps_mag.s | 18 ++++++++++ mach/i80/libem/cmpu_mag.s | 19 ++++++++++ mach/i80/ncg/table | 74 ++++----------------------------------- 3 files changed, 43 insertions(+), 68 deletions(-) create mode 100644 mach/i80/libem/cmps_mag.s create mode 100644 mach/i80/libem/cmpu_mag.s diff --git a/mach/i80/libem/cmps_mag.s b/mach/i80/libem/cmps_mag.s new file mode 100644 index 000000000..e6cbaebfb --- /dev/null +++ b/mach/i80/libem/cmps_mag.s @@ -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 index 000000000..9b6ba2b73 --- /dev/null +++ b/mach/i80/libem/cmpu_mag.s @@ -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 diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index 1cd47d652..0112eba99 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -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 -- 2.34.1