Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"It ain't over until it's over." -- Casey Stengel


devel / comp.lang.forth / Re: DEFER vs. call/forward performance

SubjectAuthor
* DEFER vs. call/forward performanceAnton Ertl
`- Re: DEFER vs. call/forward performanceAnton Ertl

1
DEFER vs. call/forward performance

<2022Jan23.085911@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16374&group=comp.lang.forth#16374

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: DEFER vs. call/forward performance
Date: Sun, 23 Jan 2022 07:59:11 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 47
Message-ID: <2022Jan23.085911@mips.complang.tuwien.ac.at>
Injection-Info: reader02.eternal-september.org; posting-host="231a70890999f0984e9e4b5f17818584";
logging-data="15495"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++ouP2+uLmzywqGep1zSVj"
Cancel-Lock: sha1:rwRahJwD3L5E13KdO+Wk8PLDKy8=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sun, 23 Jan 2022 07:59 UTC

In <2022Jan21.194651@mips.complang.tuwien.ac.at> I presented
measurements of FORWARD vs. DEFER performance on Gforth.

Here I do the same for a native-code system, in particular VFX. AFAIK
VFX has no FORWARD, but the resulting code uses a non-inlined direct
call, so I measure that, using the following microbenchmark:

defer foo2
: bar1 noop ;
: bar2 foo2 ;
' noop is foo2
: bench1 100000000 0 do bar1 bar1 bar1 bar1 bar1 bar1 bar1 bar1 bar1 bar1 loop ;
: bench2 100000000 0 do bar2 bar2 bar2 bar2 bar2 bar2 bar2 bar2 bar2 bar2 loop ;

On VFX64 BAR1 and BAR2 become:

ee bar1
BAR1
( 004E3F00 E8C329F3FF ) CALL 004168C8 NOOP
( 004E3F05 C3 ) RET/NEXT
( 6 bytes, 2 instructions )
ok
see bar2
BAR2
( 004E3F40 48FF1579FFFFFF ) CALL FFFFFF79 [RIP] @004E3EC0
( 004E3F47 C3 ) RET/NEXT
( 8 bytes, 2 instructions )

BAR1 and BAR2 are inlined in the BENCH words.

for i in 1 2; do LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u vfx64 "include bench-defer.fs bench$i bye"; done

On a Ryzen 5800X this takes the following time and instructions (per
call to BAR1/BAR2):

cyc inst
4.1 2.3 bar1
4.2 2.3 bar2

So performance is not a reason to introduce FORWARD.

- 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 2021: https://euro.theforth.net/2021

Re: DEFER vs. call/forward performance

<2022Jan23.172748@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16381&group=comp.lang.forth#16381

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: DEFER vs. call/forward performance
Date: Sun, 23 Jan 2022 16:27:48 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 38
Message-ID: <2022Jan23.172748@mips.complang.tuwien.ac.at>
References: <2022Jan23.085911@mips.complang.tuwien.ac.at>
Injection-Info: reader02.eternal-september.org; posting-host="231a70890999f0984e9e4b5f17818584";
logging-data="21917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EQGXymy7jxlREYiaEuen9"
Cancel-Lock: sha1:wnWgr8nXjZviAgUGU02/fc7OKHk=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sun, 23 Jan 2022 16:27 UTC

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
[Calling a deferred word is as fast as a non-inlined direct call]
>So performance is not a reason to introduce FORWARD.

One performance benefit of FORWARD over the idiom

defer foo
: ... foo ... ;
:noname ... ; is foo

is that calls to foo after the forward is resolved can be inlined
(this advantage is not realized in Gforth (yet), though). In order to
get the same benefit with DEFER, one can use it as follows:

defer foo
: ... foo ... ;
' foo
: foo ... ;
' foo swap defer!

and to pack this idiom in one word one can define

: :is >in @ ' >r >in ! : lastxt r> defer! ;

and then write the code above as

defer foo
: ... foo ... ;
:is foo ... ;

A standard way to do the same would need to define IS; and use it.

- 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 2021: https://euro.theforth.net/2021

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor