🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #37

Re: Pairwise dot product

#37
From: marcel hendrix
Date: Thu, 08 Oct 2026 23:51
68 lines
3976 bytes
On 10/8/2026 5:55 PM, Anton Ertl wrote:
> I discussed summing up an array with pairwise addition earlier
> <2025Jul16.132504@mips.complang.tuwien.ac.at>.  The benefits compared
> to the straightforward algorithm are:
> 
> * Better performance, because the straightforward algorithm is limited
>    by the dependence chains of the F+ computations.
> 
> * Lower rounding errors in the typical case.
> 
> The dot-product of two vectors is a primitive in linear algebra, and
> also has such a chain of F+ if implemented natively.  Implementing the
> dot product with pairwise addition should have similar benefits.
> 
> Gforth already has a word for the dot product:
> 
> |'v*' ( f-addr1 nstride1 f-addr2 nstride2 ucount - r ) gforth-0.5 "v-star"
> |   dot-product: r=v1*v2.  The first element of v1 is at f_addr1, the
> |next at f_addr1+nstride1 and so on (similar for v2).  Both vectors have
> |ucount elements.
> 
> This word is implemented as C function, which allows us to compare the
> performance of the various Forth systems to C.
> 
> I have implemented variants of v* in Forth, a straightforward one and
> one with pairwise addition.  The code can be found in
> 
> https://www.complang.tuwien.ac.at/forth/programs/pairwise-fdot.4th

[..]

> Here are the results (measured on Zen4 (Ryzen 8700G)):
> 
>     gforth-fast gforth-fast-v3     lxf            sf64          vfx64
>                              cycles:u
>   1_543_071_551  2_044_522_195                                             v*
>   6_095_056_325  6_544_418_067  3_221_307_358  4_579_918_381 3_425_243_416 st
>   4_350_367_901  4_371_526_269 10_527_316_831 10_630_319_712 1_203_870_244 pw
> 
>                             instructions:u
>   3_618_080_286  3_117_767_051                                             v*
> 11_618_280_866 11_617_967_567  9_516_121_645 17_010_999_668 6_074_024_083 st
> 10_164_410_950 10_164_097_601 14_265_222_850 16_962_950_438 3_823_084_163 pw
> 
> The Forth versions are:
> gforth-fast    current development version
> gforth-fast-v3 current development version compiled with -march=x86-64-v3
>                     this makes use of fma instructions
> lxf 1.6-982-823
> sf64 SwiftForth 4.0.0-RC89
> vfx64 5.43

[..]


> - anton

For iForth on AMD Ryzen 7 5800X 8-Core Processor
\ V*          : 2,523,563,242 clock ticks
\ naive-V*    : 2,532,810,048 clock ticks
\ pairwise-V* : 3,251,776,774 clock ticks

Using recursion to effect compilation inside an interpreted definition
( gen-v* ) is a no-no for iForth because it perceives it as nested 
compilation (which is not supported yet). It is interesting that it 
works in so many other Forths.

-marcel
Technical Details
Message-ID: <11a9aah$19g75$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <2026Oct8.175513@mips.complang.tuwien.ac.at>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: marcel hendrix <mhx@iae.nl>
Newsgroups: comp.lang.forth
Subject: Re: Pairwise dot product
Date: Fri, 9 Oct 2026 01:51:41 +0200
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <11a9aah$19g75$1@dont-email.me>
References: <2026Oct8.175513@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 08 Oct 2026 23:51:48 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1360101"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+Rw4JWTQNWwPoAvEfvjlM5H/0OhchPkLU="; posting-host="0ae84fbac74baf133a381c22de887fbc"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+XnSr73VQsuOrPsGc190EF3oPN0= sha256:o2NRR1A/uQhJyEtTkn1Y78YL1nlKDueDfYaSS5Lo9Zo=
	sha1:9p8rC+2d7y7hB3phI5Vh3SDxUYM= sha256:7zjxY5yhjqE6eoVVRA5i+Jnt3NJpWMwSf687xRwgaCA=
Content-Language: en-US
In-Reply-To: <2026Oct8.175513@mips.complang.tuwien.ac.at>