

|
 |
| Programming > Forth > Re: I found a F... |
|
| << Topic |
< Post |
Post 43 of 53 Topic 3681 of 4325
|
Post > |
Topic >> |
Re: I found a FORTH stack optimzer, but could use a better version.
by "Rod Pemberton" <do_not_have@[EMAIL PROTECTED]
>
Jan 11, 2008 at 03:34 AM
| "Jenny Brien" <jennybrien@[EMAIL PROTECTED]
> wrote in message
news:ab815318-9e67-4709-a479-a5fdae1bd429@[EMAIL PROTECTED]
> I'm interested in the minimal set needed to implement the normal Forth
> stack operators.
Then these might be of use which use rstack:
:DUP >R R@[EMAIL PROTECTED]
R>;
:SWAP >R A! R> A@[EMAIL PROTECTED]
>R DUP R> SWAP;
:ROT >R SWAP R> SWAP;
:-ROT SWAP >R SWAP >R
:NIP >R DROP R>
:TUCK >R R@[EMAIL PROTECTED]
SWAP R>;
These don't use rstack, but use simple words:
:NIP SWAP DROP;
:TUCK SWAP OVER;
Maybe these also, if you have native implementations for TUCK or NIP:
:SWAP >R TUCK DROP;
:SWAP OVER >R NIP R>;
:OVER SWAP TUCK;
:TUCK DUP -ROT;
Except for use of A! and A@[EMAIL PROTECTED]
, most of those can be found using this:
http://black.cs.bgu.ac.il/forth-opt
> Since I shall need an rstack anyway, I think adding
that to Chapman's quarks might be a reasonable compromise.
....
> To recap: The top two stack items are in registers T and N, the rest
> on the hardware stack
>
> The Quarks:
>
> DIP T=N
> DRIP N=T
> TUCK push a copy of T
> TAKE pop to T
> NUP push a copy of N
> NIP pop to N
>
Let's call the top of the physical stack Z for use below, but those are
now
in terms of Z...
TUCK push a copy of T to Z
TAKE pop Z to T
NUP push a copy of N to Z
NIP pop Z to N
> To which add:
>
> T>R push a copy of T to the rstack
> R>T pop rstack to T
> N>R push a copy of N to the rstack
> R>N pop rstack to N
>
I agree that an additional word(s), in terms of FORTH, needs to be added
at
least to implement ROT, perhaps for other operations unreviewed...e.g.,
ROLL. But, I'm not sure about the ones you just proposed.
> : ROT >R SWAP R> SWAP ; translates to the quarks
>
> T>R DIP NIP NUP DRIP TAKE NUP DRIP R>T NUP DRIP TAKE
>
> Simplification:
>
> DIP NIP NUP DRIP = DIP
> DIP TAKE = TAKE
> DRIP R>T NUP DRIP TAKE = R>N
>
> leaving R>T TAKE NUP R>N
>
Wouldn't it be easier to add a tem****ary register or variable since that's
what >R and R> effectively do? E.g., something like A! and A@[EMAIL PROTECTED]
attribute
to
MachineFORTH? SWAP is then:
:SWAP >R A! R> A@[EMAIL PROTECTED]
A! and A@[EMAIL PROTECTED]
need to be adjusted for the placement of two stack items
from
the physical stack into registers. I.e., we need A2! and A2@[EMAIL PROTECTED]
which store
and fetch Z, the top of the physical stack, into A. Then ROT becomes:
:ROT A2! NUP DRIP A2@[EMAIL PROTECTED]
TAKE;
The only further optimization I see is to create another word which does
T=A
directly, i.e., "combine" A2@[EMAIL PROTECTED]
and TAKE:
:ROT A2! NUP DRIP A2T;
All four should still be 1:1 for x86 and (hopefully) pairable on x86...
Okay, so you prefer rstack to A, then we'll need to use one of your words
above, R>T, to replace A2T. And, define one like NIP or TAKE but pops Z
to
the R stack, e.g., Z>R:
:ROT Z>R NUP DRIP R>T;
Rod Pemberton


|
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:

|
|
|
|