Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #52307
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Stack Operator Symbols |
| Date | 2016-10-30 11:01 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2016Oct30.120150@mips.complang.tuwien.ac.at> (permalink) |
| References | (1 earlier) <20161027191345.4f524e44@_> <-Lmdneii--uHXI_FnZ2dnUU7-VnNnZ2d@supernews.com> <87d1ijmwc3.fsf@nightsong.com> <lbmdnf9tpofa8YnFnZ2dnUU7-UfNnZ2d@supernews.com> <874m3un959.fsf@nightsong.com> |
Paul Rubin <no.email@nospam.invalid> writes:
>Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>> first I'd try to understand how I got into a situation which needed 3DUP.
>
>I implemented the Tak function which is a widely used Lisp benchmark:
>
> https://en.wikipedia.org/wiki/Tak_(function)
>
>I wrote a Gforth version with and without locals:
>
> : tak-locals { x y z -- n}
> y x >= if z else
> x 1- y z recurse
> y 1- z x recurse
> z 1- x y recurse
> recurse then ;
>
> : 3dup ( a b c -- a b c a b c ) >r 2dup r@ -rot r> ;
> : tak ( x y z -- n )
> -rot 2dup <=
> if
> 2drop ( z )
> else ( z x y )
> 3dup rot 1- -rot recurse >r \ tak (1- z) x y
> 3dup 1- -rot recurse >r \ tak (1- y) z x
> -rot 1- -rot recurse \ tak (1- x) y z
> r> r> recurse
> then ;
>
> : run 18 12 6 tak cr . cr ;
While this is unidiomatic, I am still interested in the performance
(mostly because there is one locals and one stack-juggling variant,
and it shows the state of locals implementation in current Forth
systems. With one fix and the inclusion of the "{" syntax for
SwiftForth, I get the following code (including calling setup);
results below.
0 [if]
for FORTH in "$HOME/gforth/gforth-fast -e" "sf include $HOME/gforth/compat/anslocal.fs" vfxlin; do echo $FORTH
perf stat -x" " -e cycles -e instructions $FORTH "include tak.4th 32 16 8 tak . cr bye"
perf stat -x" " -e cycles -e instructions $FORTH ": 3dup ( a b c -- a b c a b c ) >r 2dup r@ -rot r> ; include tak.4th 32 16 8 tak . cr bye"
perf stat -x" " -e cycles -e instructions $FORTH ": 3dup dup 2over rot ; include tak.4th 32 16 8 tak . cr bye"
perf stat -x" " -e cycles -e instructions $FORTH ": 3dup 2 pick 2 pick 2 pick ; include tak.4th 32 16 8 tak . cr bye"
perf stat -x" " -e cycles -e instructions $FORTH ": 3dup { a b c } a b c a b c ; include tak.4th 32 16 8 tak . cr bye"
perf stat -x" " -e cycles -e instructions $FORTH "include tak.4th 32 16 8 tak-locals . cr bye"
done
[then]
: tak-locals { x y z -- n }
y x >= if z else
x 1- y z recurse
y 1- z x recurse
z 1- x y recurse
recurse then ;
[undefined] 3dup [if]
: 3dup abort ;
[then]
: tak ( x y z -- n )
-rot 2dup <=
if
2drop ( z )
else ( z x y )
3dup rot 1- -rot recurse >r \ tak (1- z) x y
3dup 1- -rot recurse >r \ tak (1- y) z x
-rot 1- -rot recurse \ tak (1- x) y z
r> r> recurse
then ;
: run 18 12 6 tak cr . cr ;
And here are the results (in cycles on a Core i7-6700K):
3dup-builtin 3dup->r 3dup-2over 3dup-2pick 3dup-locals locals
gforth 1169048859 1111954861 1126237778 1236484564 1040181611
sf 472184708 608648663 565610695 533060680 1754120881 3014151164
vfxlin 490283220 467571494 412437509 401428644 723363281 699419259
Interesting results:
In sf locals is slower than 3dup-locals, and both are slower than the
same programs running on gforth.
3dup-2dup is the fastest Forth-defined version on both sf and VFX.
VFX has a builtin 3DUP, but it is slower in this benchmark than all
the Forth-defined 3DUPs; my guess is that the Forth-defined versions
work better with the inliner. For SF the builtin 3DUP is the fastest.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Stack Operator Symbols trans <transfire@gmail.com> - 2016-10-24 20:42 -0700
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-25 01:58 -0700
Re: Stack Operator Symbols november.nihal@gmail.com - 2016-10-25 10:52 -0700
Re: Stack Operator Symbols Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-10-27 19:13 -0400
Re: Stack Operator Symbols "Elizabeth D. Rather" <erather@forth.com> - 2016-10-27 17:08 -1000
Re: Stack Operator Symbols "HAA" <someone@microsoft.com> - 2016-10-28 21:53 +1000
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-28 20:42 -0700
Re: Stack Operator Symbols Walter Banks <walter@bytecraft.com> - 2016-10-29 17:15 -0400
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-29 17:27 -0700
Re: Stack Operator Symbols "Elizabeth D. Rather" <erather@forth.com> - 2016-10-28 20:56 -1000
Re: Stack Operator Symbols Paul Rubin <no.email@nospam.invalid> - 2016-10-29 00:46 -0700
Re: Stack Operator Symbols Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-10-29 04:30 -0500
Re: Stack Operator Symbols rickman <gnuarm@gmail.com> - 2016-10-29 16:58 -0400
Re: Stack Operator Symbols Paul Rubin <no.email@nospam.invalid> - 2016-10-29 14:21 -0700
Re: Stack Operator Symbols Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-10-30 04:03 -0500
Re: Stack Operator Symbols Paul Rubin <no.email@nospam.invalid> - 2016-10-30 18:06 -0700
Re: Stack Operator Symbols Spiros Bousbouras <spibou@gmail.com> - 2016-10-31 01:43 +0000
Re: Stack Operator Symbols Paul Rubin <no.email@nospam.invalid> - 2016-10-30 19:23 -0700
Re: Stack Operator Symbols Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-10-31 05:13 -0500
Re: Stack Operator Symbols albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-31 12:42 +0100
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-10-31 12:12 +0000
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-10-31 14:49 +0000
Re: Stack Operator Symbols mhx@iae.nl - 2016-10-31 13:17 -0700
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-03 16:38 +0000
Re: Stack Operator Symbols Spiros Bousbouras <spibou@gmail.com> - 2016-11-20 14:33 +0000
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-10-31 08:35 +0000
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-10-30 11:01 +0000
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-30 10:01 -0700
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-11-03 14:46 -0700
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-04 23:04 +0000
Re: Stack Operator Symbols Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-11-05 03:16 -0400
Re: Stack Operator Symbols peter.m.falth@gmail.com - 2016-10-29 09:13 -0700
Re: Stack Operator Symbols "HAA" <someone@microsoft.com> - 2016-10-30 08:47 +1100
Re: Stack Operator Symbols trans <transfire@gmail.com> - 2016-10-29 14:57 -0700
Re: Stack Operator Symbols "HAA" <someone@microsoft.com> - 2016-10-30 09:20 +1100
Re: Stack Operator Symbols Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-10-29 18:46 -0400
Re: Stack Operator Symbols Paul Rubin <no.email@nospam.invalid> - 2016-10-29 19:45 -0700
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-29 20:29 -0700
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-29 20:47 -0700
Re: Stack Operator Symbols Cecil Bayona <cbayona@cbayona.com> - 2016-10-29 23:15 -0500
Re: Stack Operator Symbols "Elizabeth D. Rather" <erather@forth.com> - 2016-10-29 21:37 -1000
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-30 10:07 -0700
Re: Stack Operator Symbols "Elizabeth D. Rather" <erather@forth.com> - 2016-10-29 21:35 -1000
Re: Stack Operator Symbols "HAA" <someone@microsoft.com> - 2016-10-31 13:11 +1100
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-30 20:02 -0700
Re: Stack Operator Symbols "Elizabeth D. Rather" <erather@forth.com> - 2016-10-30 22:08 -1000
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-10-31 09:02 +0000
Re: Stack Operator Symbols "HAA" <someone@microsoft.com> - 2016-11-03 20:49 +1100
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-03 15:33 +0000
Re: Stack Operator Symbols Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-11-03 16:55 -0400
Re: Stack Operator Symbols anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-03 22:21 +0000
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-27 20:31 -0700
Re: Stack Operator Symbols november.nihal@gmail.com - 2016-10-28 09:52 -0700
Re: Stack Operator Symbols hughaguilar96@gmail.com - 2016-10-28 20:32 -0700
Re: Stack Operator Symbols Mark Wills <markwills1970@gmail.com> - 2016-10-30 04:49 -0700
Re: Stack Operator Symbols Coos Haak <htrofhc@gmail.com> - 2016-10-30 14:49 +0100
Re: Stack Operator Symbols Matthias Koch <matthias.koch@hot.uni-hannover.de> - 2016-10-31 13:31 +0100
Re: Stack Operator Symbols Coos Haak <htrofhc@gmail.com> - 2016-10-31 14:12 +0100
Re: Stack Operator Symbols Matthias Koch <matthias.koch@hot.uni-hannover.de> - 2016-10-31 15:03 +0100
Re: Stack Operator Symbols Mark Wills <markwills1970@gmail.com> - 2016-11-03 14:22 -0700
Re: Stack Operator Symbols Coos Haak <htrofhc@gmail.com> - 2016-11-04 00:46 +0100
Re: Stack Operator Symbols "HAA" <someone@microsoft.com> - 2016-11-05 13:14 +1100
Re: Stack Operator Symbols trans <transfire@gmail.com> - 2016-10-30 06:50 -0700
Re: Stack Operator Symbols trans <transfire@gmail.com> - 2016-10-30 08:56 -0700
Re: Stack Operator Symbols albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-30 18:19 +0100
csiph-web