Merge pull request #166 from davidgiven/dtrg-comparisons

i80: grabbag of optimisations
This commit is contained in:
David Given 2019-02-15 22:54:13 +01:00 committed by GitHub
commit e1ddbf969a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 317 additions and 200 deletions

19
mach/i80/libem/cmps_mag.s Normal file
View file

@ -0,0 +1,19 @@
.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
ral ! move sign flag into carry
ret

18
mach/i80/libem/cmpu_mag.s Normal file
View file

@ -0,0 +1,18 @@
.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
ret

View file

@ -11,6 +11,9 @@
! 41 call .floadn4 ! 41 call .floadn4
! 34 call .fload4 ! 34 call .fload4
! 28 call .fstoren2 ! 28 call .fstoren2
!
! Also:
! 48 call .cmps_mag
.define .rst_init .define .rst_init
.rst_init: .rst_init:
@ -18,13 +21,12 @@
lxi d, 0x0008 lxi d, 0x0008
call copy call copy
lxi h, .floadn4 lxi h, .floadn4
lxi d, 0x0010
call copy call copy
lxi h, .fload4 lxi h, .fload4
lxi d, 0x0018
call copy call copy
lxi h, .fstoren2 lxi h, .fstoren2
lxi d, 0x0020 call copy
lxi h, .cmps_mag
jmp copy jmp copy
! Copies eight bytes from HL to DE. ! Copies eight bytes from HL to DE.
@ -34,7 +36,7 @@ copy:
mov a, m mov a, m
stax d stax d
inx h inx h
inx d inr e
dcr c dcr c
jnz .1 jnz .1
ret ret

View file

@ -157,94 +157,147 @@ INSTRUCTIONS
MOVES MOVES
from reg to reg from reg to reg
gen mov %2,%1 gen
mov %2,%1
from const1 %num==0 to areg from const1 %num==0 to areg
gen xra a gen
xra a
from const1 to reg from const1 to reg
gen mvi %2,%1 gen
mvi %2,%1
from immediate to b_d_h_sp from immediate to b_d_h_sp
gen lxi %2,%1 gen
lxi %2,%1
from reg to regpair from const1 to reg
gen mov %2.2,%1 gen
mvi %2.1,{const1,0} mvi %2, %1
from const1 to regpair
gen
mvi %2.2, %1
mvi %2.1, {const1, 0}
from regpair to regpair from reg to regpair
gen mov %2.1,%1.1 gen
mov %2.2,%1.2 mov %2.2, %1
mvi %2.1, {const1,0}
from regpair to regpair
gen
mov %2.1, %1.1
mov %2.2, %1.2
TESTS TESTS
to test areg /* dummy test, never used */ to test areg /* dummy test, never used */
gen ora a gen
ora a
STACKINGRULES STACKINGRULES
from regpair to STACK from regpair to STACK
gen push %1 gen
push %1
from immediate + reg to STACK from immediate + reg to STACK
uses hl_or_de uses hl_or_de
gen move %1,%a gen
push %a move %1, %a
push %a
from immediate + reg to STACK from immediate + reg to STACK
gen push hl gen
move %1,hl push hl
xthl. move %1, hl
xthl.
COERCIONS COERCIONS
from STACK from STACK
uses regpair uses regpair
gen pop %a yields %a gen
pop %a
yields %a
from STACK from STACK
uses hl_or_de uses hl_or_de
gen pop %a yields %a.2 gen
pop %a
yields %a.2
from STACK from STACK
uses areg uses areg
gen dcx sp gen
pop psw dcx sp
inx sp yields a pop psw
inx sp
yields %a
from immediate from immediate
uses regpair uses regpair=%1
gen move %1,%a yields %a yields %a
from hl_or_de from hl_or_de
uses hl_or_de uses hl_or_de
gen xchg. yields %a gen
xchg.
yields %a
from regpair from regpair
uses regpair uses regpair=%1
gen move %1,%a yields %a yields %a
from reg from reg
uses reusing %1, hl_or_de uses reusing %1, hl_or_de
gen move %1,%a.2 gen
move {const1,0},%a.1 yields %a move %1,%a.2
move {const1,0},%a.1
yields %a
from hl_or_de yields %1.2 from hl_or_de yields %1.2
from smallpconst2 from smallpconst2
yields {const2, %1.num} yields {const2, %1.num}
from smallnconst2 from smallnconst2
yields {const2, %1.num} yields {const2, %1.num}
from const2 from const2
uses hl_or_de uses hl_or_de=%1
gen move %1,%a yields %a.2 yields %a
from hl_or_de from smallpconst2
uses areg uses reg={const1, %1.num & 0xff}
gen move %1.2,a yields a yields %a
from smallnconst2
uses reg={const1, %1.num & 0xff}
yields %a
from smallpconst2 %1.num == 1
uses reg={const1, 0}
gen
inr %a
yields %a
from smallnconst2 %1.num == 0-1
uses reg={const1, 0}
gen
dcr %a
yields %a
from const2
uses reg={const1, %1.num & 0xff}
yields %a
from hl_or_de
uses reg=%1.2
yields %a
PATTERNS PATTERNS
@ -569,13 +622,15 @@ pat stf
mov {m},d mov {m},d
pat sti $1==1 pat sti $1==1
with label areg with label areg
gen sta %1 gen
with dereg areg sta %1
gen stax de with dereg areg
with hlreg reg gen
gen mov {m},%2 stax %1
with hlreg reg
gen
mov {m}, %2
pat sti $1==2 pat sti $1==2
with label hlreg with label hlreg
@ -1618,6 +1673,70 @@ leaving cal ".cmf4" asp 8 lfr 2
pat cmf $1==8 pat cmf $1==8
leaving cal ".cmf8" asp 16 lfr 2 leaving cal ".cmf8" asp 16 lfr 2
pat cmu zlt $1==2
with hl_or_de hl_or_de STACK
uses areg
gen
mov a, %2.2
sub %1.2
mov a, %2.1
sbb %1.1
jc {label, $2}
with const2 hl_or_de 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 hl_or_de 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 hl_or_de hl_or_de STACK
uses areg
gen
mov a, %2.2
sub %1.2
mov a, %2.1
sbb %1.1
jnc {label, $2}
with const2 hl_or_de 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 hl_or_de 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 pat cmu $1==2
with hl_or_de hl_or_de with hl_or_de hl_or_de
uses areg uses areg
@ -1875,42 +1994,15 @@ pat bra
jmp {label,$1} jmp {label,$1}
pat blt pat blt
with const2 hl_or_de STACK with hlreg dereg STACK
uses areg uses areg
gen gen
mov a, %2.1 #ifdef USE_I80_RSTS
xri {const1, 0x80} rst {const1, 5}
mov %2.1, a #else
mov a, %2.2 Call {label, ".cmps_mag"}
sui {const1, %1.num & 0xff} #endif
mov a, %2.1
sbi {const1, (%1.num >> 8) ^ 0x80}
jc {label, $1} 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
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}
pat bgt pat bgt
leaving leaving
@ -1918,42 +2010,15 @@ pat bgt
blt $1 blt $1
pat bge pat bge
with const2 hl_or_de STACK with hlreg dereg STACK
uses areg uses areg
gen gen
mov a, %2.1 #ifdef USE_I80_RSTS
xri {const1, 0x80} rst {const1, 5}
mov %2.1, a #else
mov a, %2.2 Call {label, ".cmps_mag"}
sui {const1, %1.num & 0xff} #endif
mov a, %2.1
sbi {const1, (%1.num >> 8) ^ 0x80}
jnc {label, $1} 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
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}
pat ble pat ble
leaving leaving
@ -2011,62 +2076,68 @@ pat bne
jnz {label,$1} jnz {label,$1}
pat zlt pat zlt
with STACK with STACK
gen pop psw gen
ora a pop psw
jm {label,$1} ora a
with hl_or_de STACK jm {label,$1}
gen mov a,%1.1 with hl_or_de STACK
ora a gen
jm {label,$1} mov a,%1.1
ora a
jm {label,$1}
pat zle pat zle
with hl_or_de STACK with hl_or_de STACK
uses areg uses areg
gen xra a gen
add %1.1 mov a, %1.1
jm {label,$1} ora a
jnz {label,1f} jm {label, $1}
xra a jnz {label, 1f}
add %1.2 ora %1.2
jz {label,$1} jz {label, $1}
1: 1:
pat zeq pat zeq
with hl_or_de STACK with hl_or_de STACK
uses areg uses areg
gen mov a,%1.1 gen
ora %1.2 mov a,%1.1
jz {label,$1} ora %1.2
jz {label,$1}
pat zne pat zne
with hl_or_de STACK with hl_or_de STACK
uses areg uses areg
gen mov a,%1.1 gen
ora %1.2 mov a,%1.1
jnz {label,$1} ora %1.2
jnz {label,$1}
pat zge pat zge
with STACK with STACK
gen pop psw gen
ral. pop psw
jnc {label,$1} ral.
with hl_or_de STACK jnc {label,$1}
gen mov a,%1.1 with hl_or_de STACK
ora a gen
jp {label,$1} mov a,%1.1
ora a
jp {label,$1}
pat zgt pat zgt
with hl_or_de STACK with hl_or_de STACK
uses areg uses areg
gen xra a gen
add %1.1 mov a, %1.1
jm {label,1f} ora a
jnz {label,$1} jm {label, 1f}
xra a jnz {label, $1}
add %1.2 ora %1.2
jnz {label,$1} jnz {label, $1}
1: 1:
pat lol zeq pat lol zeq
with STACK with STACK
@ -2089,22 +2160,24 @@ pat lol zne
jnz {label,$2} jnz {label,$2}
pat ior zeq $1==2 pat ior zeq $1==2
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK
uses areg uses areg
gen mov a,%1.1 gen
ora %1.2 mov a,%1.1
ora %2.1 ora %1.2
ora %2.2 ora %2.1
jz {label,$2} ora %2.2
jz {label,$2}
pat ior zne $1==2 pat ior zne $1==2
with hl_or_de hl_or_de STACK with hl_or_de hl_or_de STACK
uses areg uses areg
gen mov a,%1.1 gen
ora %1.2 mov a,%1.1
ora %2.1 ora %1.2
ora %2.2 ora %2.1
jnz {label,$2} ora %2.2
jnz {label,$2}
/*********************************************/ /*********************************************/
/* Group 14: Procedure call instructions */ /* Group 14: Procedure call instructions */
@ -2165,14 +2238,14 @@ gen 1:
pat asp $1==0 /* do nothing */ pat asp $1==0 /* do nothing */
pat asp ($1==2) pat asp ($1==2)
with regpair with hl_or_de
with STACK with STACK
uses hlreg uses hlreg
gen gen
pop hl pop hl
pat asp ($1==4) pat asp ($1==4)
with regpair regpair with hl_or_de hl_or_de
with STACK with STACK
uses hlreg uses hlreg
gen gen

View file

@ -16,4 +16,9 @@ xchg : inx d : xchg -> inx h ;
cpi 0 -> ora a ; cpi 0 -> ora a ;
call X : ret -> jmp X ; 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 ;
%%; %%;