Compare commits

...

4 Commits

Author SHA1 Message Date
Virgil Dupras 85a0b87da3 z80: reorder compiledWord and doesWord, saving ourselves a jump 2020-06-14 10:12:56 -04:00
Virgil Dupras 38d5a9f303 z80: inline cellWord in stable ABI 2020-06-14 10:07:46 -04:00
Virgil Dupras 40f92b9bab z80: optimize chkPS
Inline it in next and make chkPS, call a newly reserved label for
it directly, removing a layer of indirection. This frees a spot in
the stable ABI.
2020-06-14 09:48:10 -04:00
Virgil Dupras 31095bc04d z80: remove call indirections in tight spots 2020-06-14 09:29:34 -04:00
12 changed files with 60 additions and 92 deletions

View File

@ -1,7 +1,7 @@
: OP1 CREATE C, DOES> C@ A, ;
0xf3 OP1 DI, 0xfb OP1 EI,
0xeb OP1 EXDEHL, 0xd9 OP1 EXX,
0x08 OP1 EXAFAF',
0x08 OP1 EXAFAF', 0xe3 OP1 EX(SP)HL,
0x76 OP1 HALT, 0xe9 OP1 JP(HL),
0x12 OP1 LD(DE)A, 0x1a OP1 LDA(DE),
0x02 OP1 LD(BC)A, 0x0a OP1 LDA(BC),

View File

@ -5,7 +5,7 @@
: JPNEXT, 26 BJP, ; ( 26 == next )
: chkPS, 29 BCALL, ; ( 29 == chkPS )
: chkPS, L4 @ BCALL, ; ( chkPS, B305 )
: CODE ( same as CREATE, but with native word )
(entry)

View File

@ -1,11 +1,12 @@
H@ ORG !
0 JPnn, ( 00, main ) 0 JPnn, ( 03, find )
NOP, NOP, ( 06, unused ) NOP, NOP, ( 08, LATEST )
NOP, ( 0a, unused ) 0 JPnn, ( 0b, cellWord )
NOP, ( 0a, unused )
( 0b cellWord, push PFA ) DE PUSHqq, JR, 0x0c A, ( next )
0 JPnn, ( 0e, compiledWord ) 0 JPnn, ( 11, pushRS )
0 JPnn, ( 14, popRS )
EXDEHL, JP(HL), NOP, ( 17, nativeWord )
0 JPnn, ( 1a, next ) 0 JPnn, ( 1d, chkPS )
0 JPnn, ( 1a, next ) 0 JPnn, ( unused )
NOP, NOP, ( 20, numberWord ) NOP, NOP, ( 22, litWord )
NOP, NOP, ( 24, addrWord ) NOP, NOP, ( 26, unused )
0 JPnn, ( RST 28 )
@ -13,4 +14,3 @@ NOP, NOP, ( 24, addrWord ) NOP, NOP, ( 26, unused )
0 JPnn, ( RST 30 )
0 JPnn, ( 33, execute ) NOP, NOP, ( unused )
0 JPnn, ( RST 38 )

View File

@ -1,4 +1,4 @@
PC ORG @ 0x12 + ! ( pushRS )
L4 BSET PC ORG @ 0x12 + ! ( pushRS )
IX INCss,
IX INCss,
0 IX+ L LDIXYr,

16
blk/299
View File

@ -1,16 +0,0 @@
PC ORG @ 0x1e + ! ( chkPS )
( Note that you only need to call this in words that push
back to PSP. If they don't, calling chkPS is redundant with
check in next )
EXX,
( We have the return address for this very call on the stack
and protected registers. 2 - is to compensate that. )
HL PS_ADDR 2 - LDddnn,
SP SUBHLss,
EXX,
CNC RETcc, ( PS_ADDR >= SP? good )
JR, L2 BWR ( abortUnderflow-B298 )

10
blk/300
View File

@ -3,14 +3,14 @@ PC ORG @ 0x1b + ! ( next )
we jump to current IP, but we also take care of increasing
it by 2 before jumping. )
( Before we continue: are stacks within bounds? )
0x1d BCALL, ( chkPS )
( check RS )
IX PUSHqq, HL POPqq,
( PS ) HL PS_ADDR LDddnn,
SP SUBHLss,
JRC, L2 BWR ( abortUnderflow-B298 )
( RS ) IX PUSHqq, HL POPqq,
DE RS_ADDR LDddnn,
DE SUBHLss,
JRC, L2 BWR ( IX < RS_ADDR? abortUnderflow-B298 )
E 0 IY+ LDrIXY,
D 1 IY+ LDrIXY,
IY INCss,
IY INCss,
IY INCss, IY INCss,
( continue to execute )

28
blk/302
View File

@ -1,16 +1,16 @@
L1 BSET PC ORG @ 0x0f + ! ( compiledWord )
( 1. Push current IP to RS
2. Set new IP to the second atom of the list
3. Execute the first atom of the list. )
IY PUSHqq, HL POPqq, ( <-- IP )
0x11 BCALL, ( 11 == pushRS )
EXDEHL, ( HL points to PFA )
( While we inc, dereference into DE for execute call later. )
LDDE(HL),
PC ORG @ 0x2c + ! ( doesWord )
( The word was spawned from a definition word that has a
DOES>. PFA+2 (right after the actual cell) is a link to the
slot right after that DOES>. Therefore, what we need to do
push the cell addr like a regular cell, then follow the
linkfrom the PFA, and then continue as a regular
compiledWord. )
DE PUSHqq, ( like a regular cell )
EXDEHL,
HL INCss,
HL PUSHqq, IY POPqq, ( --> IP )
JR, L3 BWR ( execute-B301 )
HL INCss,
E (HL) LDrr,
HL INCss,
D (HL) LDrr,
( continue to compiledWord )

24
blk/303
View File

@ -1,15 +1,15 @@
PC ORG @ 0x0c + ! ( cellWord )
( Pushes PFA directly )
DE PUSHqq,
JPNEXT,
PC ORG @ 0x0f + ! ( compiledWord )
( 1. Push current IP to RS
2. Set new IP to the second atom of the list
3. Execute the first atom of the list. )
IY PUSHqq, HL POPqq, ( <-- IP )
L4 @ ( pushRS ) BCALL,
EXDEHL, ( HL points to PFA )
( While we inc, dereference into DE for execute call later. )
LDDE(HL),
HL INCss,
HL PUSHqq, IY POPqq, ( --> IP )
JR, L3 BWR ( execute-B301 )

16
blk/304
View File

@ -1,16 +0,0 @@
PC ORG @ 0x2c + ! ( doesWord )
( The word was spawned from a definition word that has a
DOES>. PFA+2 (right after the actual cell) is a link to the
slot right after that DOES>. Therefore, what we need to do
push the cell addr like a regular cell, then follow the
linkfrom the PFA, and then continue as a regular
compiledWord. )
DE PUSHqq, ( like a regular cell )
EXDEHL,
HL INCss,
HL INCss,
E (HL) LDrr,
HL INCss,
D (HL) LDrr,
JR, L1 BWR ( compiledWord-B302 )

24
blk/305
View File

@ -1,15 +1,15 @@
( Core words )
( KEY and EMIT are not defined here. There're
expected to be defined in platform-specific code. )
CODE EXECUTE
DE POPqq,
chkPS,
JR, L3 BWR ( execute-B301 )
L4 BSET ( chkPS )
( Note that you only need to call this in words that push
back to PSP. If they don't, calling chkPS is redundant with
check in next )
EXX,
( We have the return address for this very call on the stack
and protected registers. 2 - is to compensate that. )
HL PS_ADDR 2 - LDddnn,
SP SUBHLss,
EXX,
CNC RETcc, ( PS_ADDR >= SP? good )
JR, L2 BWR ( abortUnderflow-B298 )

22
blk/306
View File

@ -1,16 +1,16 @@
( Core words )
( KEY and EMIT are not defined here. There're
expected to be defined in platform-specific code. )
CODE EXECUTE
DE POPqq,
chkPS,
JR, L3 BWR ( execute-B301 )
( a b c -- b c a )
CODE ROT
HL POPqq, ( C )
DE POPqq, ( B )
BC POPqq, ( A )
HL POPqq, ( C ) DE POPqq, ( B ) BC POPqq, ( A )
chkPS,
DE PUSHqq, ( B )
HL PUSHqq, ( C )
BC PUSHqq, ( A )
DE PUSHqq, ( B ) HL PUSHqq, ( C ) BC PUSHqq, ( A )
;CODE

Binary file not shown.