m_l_g3@[EMAIL PROTECTED]
wrote:
> On Mar 9, 7:27 am, Krishna Myneni <krishnamyn...@[EMAIL PROTECTED]
> wrote:
>> 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,
>
>
> Recoding } in assembly would give you another 8% (or, maybe, even
> 11% ;-)
> ****table code almost never happens to be the fastest possible.
>
> What sort of application/benchmark it was?
>
>
Unfortunately we have not reached the fastest potentially ****table
implementation yet.
The recoding to inline "CELL-" in the definition of "}" gave nearly an 18%
increase in speed under Gforth. This is without resorting to assembly
language.
Note that we have only inlined the word "CELL-". However, the word "}"
should
really be declared to be an inline word (there's no easy ****table way to
do this
now), and we will obtain an even greater performance increase.
The application is a curve-fitting program which fits a set of 513 points
to a
function consisting of two Gaussian curves plus a baseline. See the
program
gfit-curvefit.fs
in the directory
ftp://ccreweb.org/software/gforth/fsl/demo/
Additional files needed are:
fsl-util.fs
dynmem.fs
gaussj.fs
curvefit.fs (from .../fsl/extras/)
func_Ngauss.fs (from .../fsl/demo/)
wfms01-1.dat (data file from .../fsl/demo)
The test code is
: test x{ y{ a{ deltaa{ npar np curvefit fdrop ;
The word TEST executes one iteration of the curve fitting algorithm
(Levenberg-Marquardt), without displaying any output. To time its
execution, use
MS@[EMAIL PROTECTED]
TEST MS@[EMAIL PROTECTED]
SWAP - .
where MS@[EMAIL PROTECTED]
exists in several Forth systems, and can be defined in Gforth as
: ms@[EMAIL PROTECTED]
( -- u ) utime 1 1000 m*/ d>s ;
Cheers,
Krishna


|