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

View file

@ -158,42 +158,61 @@ INSTRUCTIONS
MOVES
from reg to reg
gen mov %2,%1
gen
mov %2,%1
from const1 %num==0 to areg
gen xra a
gen
xra a
from const1 to reg
gen mvi %2,%1
gen
mvi %2,%1
from immediate to b_d_h_sp
gen lxi %2,%1
gen
lxi %2,%1
from const1 to reg
gen
mvi %2, %1
from const1 to regpair
gen
mvi %2.2, %1
mvi %2.1, {const1, 0}
from reg to regpair
gen mov %2.2,%1
gen
mov %2.2, %1
mvi %2.1, {const1,0}
from regpair to regpair
gen mov %2.1,%1.1
gen
mov %2.1, %1.1
mov %2.2, %1.2
TESTS
to test areg /* dummy test, never used */
gen ora a
gen
ora a
STACKINGRULES
from regpair to STACK
gen push %1
gen
push %1
from immediate + reg to STACK
uses hl_or_de
gen move %1,%a
gen
move %1, %a
push %a
from immediate + reg to STACK
gen push hl
gen
push hl
move %1, hl
xthl.
@ -201,34 +220,44 @@ COERCIONS
from STACK
uses regpair
gen pop %a yields %a
gen
pop %a
yields %a
from STACK
uses hl_or_de
gen pop %a yields %a.2
gen
pop %a
yields %a.2
from STACK
uses areg
gen dcx sp
gen
dcx sp
pop psw
inx sp yields a
inx sp
yields %a
from immediate
uses regpair
gen move %1,%a yields %a
uses regpair=%1
yields %a
from hl_or_de
uses hl_or_de
gen xchg. yields %a
gen
xchg.
yields %a
from regpair
uses regpair
gen move %1,%a yields %a
uses regpair=%1
yields %a
from reg
uses reusing %1, hl_or_de
gen move %1,%a.2
move {const1,0},%a.1 yields %a
gen
move %1,%a.2
move {const1,0},%a.1
yields %a
from hl_or_de yields %1.2
@ -239,12 +268,36 @@ from smallnconst2
yields {const2, %1.num}
from const2
uses hl_or_de
gen move %1,%a yields %a.2
uses hl_or_de=%1
yields %a
from smallpconst2
uses reg={const1, %1.num & 0xff}
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 areg
gen move %1.2,a yields a
uses reg=%1.2
yields %a
PATTERNS
@ -570,12 +623,14 @@ pat stf
pat sti $1==1
with label areg
gen sta %1
gen
sta %1
with dereg areg
gen stax de
gen
stax %1
with hlreg reg
gen mov {m},%2
gen
mov {m}, %2
pat sti $1==2
with label hlreg
@ -1618,6 +1673,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 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
with hl_or_de hl_or_de
uses areg
@ -1875,41 +1994,14 @@ pat bra
jmp {label,$1}
pat blt
with const2 hl_or_de STACK
with hlreg dereg 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
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
#ifdef USE_I80_RSTS
rst {const1, 5}
#else
Call {label, ".cmps_mag"}
#endif
jc {label, $1}
pat bgt
@ -1918,41 +2010,14 @@ pat bgt
blt $1
pat bge
with const2 hl_or_de STACK
with hlreg dereg 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
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
#ifdef USE_I80_RSTS
rst {const1, 5}
#else
Call {label, ".cmps_mag"}
#endif
jnc {label, $1}
pat ble
@ -2012,59 +2077,65 @@ pat bne
pat zlt
with STACK
gen pop psw
gen
pop psw
ora a
jm {label,$1}
with hl_or_de STACK
gen mov a,%1.1
gen
mov a,%1.1
ora a
jm {label,$1}
pat zle
with hl_or_de STACK
uses areg
gen xra a
add %1.1
gen
mov a, %1.1
ora a
jm {label, $1}
jnz {label, 1f}
xra a
add %1.2
ora %1.2
jz {label, $1}
1:
pat zeq
with hl_or_de STACK
uses areg
gen mov a,%1.1
gen
mov a,%1.1
ora %1.2
jz {label,$1}
pat zne
with hl_or_de STACK
uses areg
gen mov a,%1.1
gen
mov a,%1.1
ora %1.2
jnz {label,$1}
pat zge
with STACK
gen pop psw
gen
pop psw
ral.
jnc {label,$1}
with hl_or_de STACK
gen mov a,%1.1
gen
mov a,%1.1
ora a
jp {label,$1}
pat zgt
with hl_or_de STACK
uses areg
gen xra a
add %1.1
gen
mov a, %1.1
ora a
jm {label, 1f}
jnz {label, $1}
xra a
add %1.2
ora %1.2
jnz {label, $1}
1:
@ -2091,7 +2162,8 @@ pat lol zne
pat ior zeq $1==2
with hl_or_de hl_or_de STACK
uses areg
gen mov a,%1.1
gen
mov a,%1.1
ora %1.2
ora %2.1
ora %2.2
@ -2100,7 +2172,8 @@ gen mov a,%1.1
pat ior zne $1==2
with hl_or_de hl_or_de STACK
uses areg
gen mov a,%1.1
gen
mov a,%1.1
ora %1.2
ora %2.1
ora %2.2
@ -2165,14 +2238,14 @@ gen 1:
pat asp $1==0 /* do nothing */
pat asp ($1==2)
with regpair
with hl_or_de
with STACK
uses hlreg
gen
pop hl
pat asp ($1==4)
with regpair regpair
with hl_or_de hl_or_de
with STACK
uses hlreg
gen

View file

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