Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: locals slowness in sf and vfx (was: SEND+MORE=MONEY)
Date: Thu, 09 Feb 2023 17:13:54 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 30
Message-ID: <2023Feb9.181354@mips.complang.tuwien.ac.at>
References: <78cfcd0a-5bc4-4584-8a92-9e8005a0e306n@googlegroups.com> <87ttzvzmmb.fsf@nightsong.com> <2023Feb9.084758@mips.complang.tuwien.ac.at> <138b28de-6f2a-449b-9279-629f3c17a03bn@googlegroups.com> <2023Feb9.115420@mips.complang.tuwien.ac.at>
Injection-Info: reader01.eternal-september.org; posting-host="4a23064dba6cc3b448d0d7b13f318f12";
	logging-data="790587"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/ZWsfxH1vfQXUR3xommyNa"
Cancel-Lock: sha1:LcXNgSskggvHCsYhY6TXgCioi6Y=
X-newsreader: xrn 10.11
Bytes: 2373

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>The lxf result demonstrates that locals can be implemented much more
>efficiently than in VFX or in SwiftForth.

One reason for the slowness of VFX and SwiftForth is that they produce
many more branch mispredictions (on Zen3):

      lxf       sf 4.0.0 RC52 vfx64 5.11 RC2
1_661_643_918   5_213_828_602  6_905_863_327 cycles:u
5_033_144_481  11_408_344_624  9_084_604_276 instructions:u
    4_371_603      70_048_027     72_169_382 branch-misses

http://www.complang.tuwien.ac.at/forth/programs/sendmore.fth

A misprediction typically costs 20 cycles, so the 66M-68M additional
mispredictions cost 1.3G-1.4G cycles which does not explain all of the
slowdown, but a good part of it.

These mispredictions are caused by the technique of pushing an
additional return address that returns to other code than that where
the last call came from.  The hardware return stack for branch
prediction was introduced at least 25 years ago, it's time that Forth
systems accept that reality and let go of this technique.

- 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: https://forth-standard.org/
   EuroForth 2022: https://euro.theforth.net