

|
 |
| Programming > Forth > Re: I found a F... |
|
| << Topic |
< Post |
Post 7 of 53 Topic 3681 of 4236
|
Post > |
Topic >> |
Re: I found a FORTH stack optimzer, but could use a better version.
by mhx@[EMAIL PROTECTED]
(Marcel Hendrix)
Jan 6, 2008 at 12:58 PM
| "Rod Pemberton" <do_not_have@[EMAIL PROTECTED]
> writes Re: I found a FORTH
stack optimzer, but could use a better version.
> "Marcel Hendrix" <mhx@[EMAIL PROTECTED]
> wrote in message
news:02231217223559@[EMAIL PROTECTED]
>> In a Forth optimizing compiler, stack words (in almost all cases for
>> "sane" code) do not generate any code. Such words do not do any
>> useful "work," they just reorder the stack for words that do, and
>> instruction/address mode selection will take care of it.
> Well, they either have an allocator that keeps track of the adjusted
> position of elements on the stack or they must manually move "cells"
around
> on the stack, correct?
Yes.
> Let's see, Dr. CH Ting's eForth (36 primitives) has 11 stack
> operators as primitives. Mikael Patel's minimal FORTH machine
> (9 primitives) has 6 stack operators as primitives. Mark Hayes
> MRFORTH (23 primitives) has 6 stack operators as primitives.
> Koopman's high execution frequency list has 5 stack operators.
> GNU GFORTH has (46 primitives) has 16 stack operators as
> primitives.
> I guess the old and simple ones aren't too "sane"... :-)
> Of course, they aren't STC either but DTC or ITC.
I think there is a misunderstanding here. The primitives of these old,
non-optimizing, Forths are just fine. When I said
>> stack words (in almost all cases for "sane" code) do not generate
>> any code.
.... the "sane" part is not making making fun of these classic
compilers. What I mean with "sane" code is Forth source code with
a limited number of integer and float stack entries (like 3, maybe
more when there are double parameters [e.g. strings]). For example,
A word which uses "4 ROLL" or "5 PICK 7 PICK" or "2>R >R >R 6 PICK
>R 2R>" is not considered sane by me.
Now, with that definition of "sane Forth code," an optimizing Forth
compiler will succeed in removing (behind the scenes) all uses of
Forth stack operators. That does not mean that such a compiler does
not have DUP SWAP or NIP as primitives (e.g. because it needs to handle
DEFER xt ' SWAP IS xt ...). OTOH, if your perform run-time profiling
and find high counts for DUP, ROT etc., then probably either your
"optimizing Forth compiler" or your profiler is no good.
Example:
iForth version 2.1.2740, generated 20:57:59, December 27, 2007.
x86 binary, native floating-point, double precision.
Copyright 1996 - 2008 Marcel Hendrix.
FORTH> : word1 over over -rot dup + + + - ; ok
FORTH> see word1
Flags: TOKENIZE, ANSI
: word1 OVER OVER -ROT DUP + + + - ; ok
FORTH> : test 1 2 word1 drop ; ok
FORTH> see test
Flags: TOKENIZE, ANSI
: test 1 2 word1 DROP ; ok
FORTH> ' test idis ( disassemble generated code )
$005564C0 : [trashed]
$005564C8 ;
( no generated code for test )
-marcel


|
53 Posts in Topic:
|
"Rod Pemberton" |
2008-01-06 00:26:01 |
|
mhx@[EMAIL PROTECTED]
(M |
2008-01-06 09:22:17 |
|
"Rod Pemberton" |
2008-01-06 04:37:47 |
|
mhx@[EMAIL PROTECTED]
(M |
2008-01-06 11:00:53 |
|
"Rod Pemberton" |
2008-01-06 06:10:48 |
|
"Rod Pemberton" |
2008-01-06 06:24:17 |
|
mhx@[EMAIL PROTECTED]
(M |
2008-01-06 12:58:34 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 08:27:20 |
|
Coos Haak <chforth@[EM |
2008-01-06 21:16:07 |
|
"Ed" <nospam |
2008-01-07 17:51:08 |
|
Albert van der Horst < |
2008-01-07 17:22:03 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 13:00:32 |
|
none <""jan\ |
2008-01-06 14:07:31 |
|
mhx@[EMAIL PROTECTED]
(M |
2008-01-06 15:27:04 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 08:32:53 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 08:05:30 |
|
stephenXXX@[EMAIL PROTECT |
2008-01-06 13:42:55 |
|
"Rod Pemberton" |
2008-01-06 06:09:25 |
|
stephenXXX@[EMAIL PROTECT |
2008-01-06 13:46:06 |
|
"Rod Pemberton" |
2008-01-06 18:25:08 |
|
stephenXXX@[EMAIL PROTECT |
2008-01-07 10:58:44 |
|
"Rod Pemberton" |
2008-01-07 21:39:25 |
|
"Rod Pemberton" |
2008-01-07 22:57:58 |
|
Albert van der Horst < |
2008-01-08 08:13:03 |
|
"Rod Pemberton" |
2008-01-08 05:07:03 |
|
Albert van der Horst < |
2008-01-08 18:26:32 |
|
Alex McDonald <blog@[E |
2008-01-08 03:04:52 |
|
Roelf Toxopeus <these3 |
2008-01-06 15:24:29 |
|
winston19842005 <bjjly |
2008-01-06 10:13:11 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 08:01:26 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 08:52:02 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 08:54:01 |
|
Bernd Paysan <bernd.pa |
2008-01-06 18:34:43 |
|
helmwo@[EMAIL PROTECTED]
|
2008-01-06 10:27:48 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 13:26:05 |
|
Bernd Paysan <bernd.pa |
2008-01-06 23:02:25 |
|
kenney@[EMAIL PROTECTED]
|
2008-01-07 09:47:13 |
|
foxchip <fox@[EMAIL PR |
2008-01-06 13:43:00 |
|
Jenny Brien <jennybrie |
2008-01-08 14:06:38 |
|
Bill <bill@[EMAIL PROT |
2008-01-08 21:20:47 |
|
"Rod Pemberton" |
2008-01-09 04:57:34 |
|
Jenny Brien <jennybrie |
2008-01-10 09:50:29 |
|
"Rod Pemberton" |
2008-01-11 03:34:02 |
|
"Jenny Brien" & |
2008-01-11 17:49:07 |
|
"Rod Pemberton" |
2008-01-12 04:31:21 |
|
astrobe <fdubois76@[EM |
2008-01-14 09:31:33 |
|
foxchip <fox@[EMAIL PR |
2008-01-19 10:11:10 |
|
stephenXXX@[EMAIL PROTECT |
2008-01-20 15:33:32 |
|
ygrek <ygrek@[EMAIL PR |
2008-01-06 12:31:47 |
|
"Rod Pemberton" |
2008-01-06 17:58:45 |
|
anton@[EMAIL PROTECTED]
|
2008-01-06 18:22:00 |
|
"Rod Pemberton" |
2008-01-06 18:18:56 |
|
ygrek <ygrek@[EMAIL PR |
2008-01-07 09:05:18 |
|
Post A Reply:

|
|
|
|