[PicForth] Re: -! optimisation problem
David McNab
david at rebirthing.co.nz
Tue Dec 7 02:19:05 CET 2004
Samuel Tardieu wrote:
> Great! When you upload your new version on the wiki, I'll be happy to
> add it either in PicForth or as a test case, to make sure that there
> are no regressions.
new lib3, pure-picforth version, now uploaded to wiki
> When I wrote that the two operations were
> equivalent, I was not talking about the status bits whose behaviour
> are not covered by Forth :-)
This exposes a philosophical question.
The fact that status bits like z, c etc are readily settable/testable
from PicForth might tempt some people to debate that assertion.
IMHO, a good position might be to document the impact of the various
PicForth words on the status bits (wherever the impact is clear and
deterministic).
As you can see from lib3, access to the status bits is an absolute
necessity when dealing in number sizes greater than 8 bits.
Also, in general, access to Z and C from pure-picforth code can produce
much more optimal code. For instance, incrementing a counter variable,
and doing something whenever the count reaches zero.
The construct:
1 somevar +!
z bit-set? if
do-something
then
produces:
0x0005 0AA2 incf 0x22,f
0x0006 1903 btfsc 0x03,2
0x0007 2804 goto 0x004 ; do-something
while:
1 somevar +!
somevar @ 0= if
do-something
then
produces:
0x0009 0AA2 incf 0x22,f
0x000A 0822 movf 0x22,w
0x000B 1903 btfsc 0x03,2
0x000C 2804 goto 0x004 ; do-something
which takes an extra mword.
(Hey, there might be scope to add an optimiser rule which uses incfsz
etc where possible).
--
Cheers
David
More information about the PicForth
mailing list