Krishna Myneni wrote:
> Anybody know a good reason for the presence of SWAP in the following
> word, from fsl-util.xxx?
>
> : } ( addr n -- addr[n]) \ word that fetches 1-D array addresses
> OVER CELL- @[EMAIL PROTECTED]
> * SWAP +
> ;
>
> Also, do the native code optimizing compilers eliminate the unnecessary
> SWAP in the compiled code?
>
> Krishna
Recoding "}" to remove the frivolous SWAP, and manually inlining the word
CELL-
gave roughly an 8% improvement in performance, in kForth, for a curve
fitting
routine which uses array indexing heavily. The above definition of "}" is
replaced by
: } OVER [ 1 CELLS ] LITERAL - @[EMAIL PROTECTED]
* + ;
Normally, a word like CELL- should be inlined, but because there are no
provisions for macros in the FSL, inline words can't be defined ****tably
within
the framework of fsl-util.x. Most of the speedup comes not from dropping
the
SWAP, but from inlining the word CELL-.
OFF THIS TOPIC: it would be nice if Forth 200x would standardize a keyword
for
denoting inline words, e.g.
: CELL- [ 1 CELLS ] LITERAL - ; inline
A Forth implementation could choose to ignore the keyword, or to give the
marked
word appropriate compile time behavior. Macros could then be avoided in a
lot of
situations. I seem to remember from Stroustrup's book that he added such a
keyword in C++ because of common pitfalls with macros in C.
Krishna


|