🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #45

Re: Pairwise dot product

#45
From: Anton Ertl
Date: Fri, 09 Oct 2026 07:20
87 lines
5232 bytes
marcel hendrix <mhx@iae.nl> writes:
>On 10/9/2026 7:32 AM, Anton Ertl wrote:
>[..]> It does not nest definitions, so it's unclear why it should be
>> perceived as nested definitions.
>
>The latest iForth checks [ and ] for (not) increasing the code space
>in a way that night impact doing nested compilation. It gives a stack 
>error that looks like a problem with CASE's branch generator . I will 
>investigate further when I have time. Thanks for reporting.

There's a theory that generating code in interpretation state is
non-standard.  I think that this is a poor proxy for checking whether
code is generated inside a colon definition.  But anyway, if your
system implements some check against that, one way to work around that
is to make gen-v* immediate and replace the sequences "gen-v* ]" with
"] gen-v*".

>>     gf-f     gf-f-v3    iForth     lxf       sf64       vfx64
>>                           k cycles:u
>>   1_543_608  2_043_449                                          v*
>>   6_090_505  6_544_524 3_399_183 3_219_799  4_705_232 3_425_833 naive-v*
>>   4_355_047  4_360_980 3_850_466 4_368_398 11_998_171 1_208_370 pairwise-v*
>
>The most interesting result is the very good result of Gforth's native 
>v*

The inner loop of that is:

   $563ABF4BD990: movsd  (%rdi),%xmm0
   $563ABF4BD994: mulsd  (%rdx),%xmm0
   $563ABF4BD998: add    %rsi,%rdi
   $563ABF4BD99B: add    %rcx,%rdx
   $563ABF4BD99E: addsd  %xmm0,%xmm1
   $563ABF4BD9A2: sub    $0x1,%r8
   $563ABF4BD9A6: jne    0x563abf4bd990

Ideally, a Forth system compile NAIVE-V* to code that has a similar
inner loop.

>and vfx64's surprising sprint in pairwise-v*.

VFX generates good code for v*1...v*64, e.g., v*2:

( 0050AB40    DD03 )                  FLD     DOUBLE 0 [RBX]
( 0050AB42    488B5500 )              MOV     RDX, [RBP]
( 0050AB46    DD02 )                  FLD     DOUBLE 0 [RDX]
( 0050AB48    DEC9 )                  FMULP   ST(1), ST
( 0050AB4A    488B5500 )              MOV     RDX, [RBP]
( 0050AB4E    48035510 )              ADD     RDX, [RBP+10]
( 0050AB52    48035D08 )              ADD     RBX, [RBP+08]
( 0050AB56    DD03 )                  FLD     DOUBLE 0 [RBX]
( 0050AB58    DD02 )                  FLD     DOUBLE 0 [RDX]
( 0050AB5A    DEC9 )                  FMULP   ST(1), ST
( 0050AB5C    48035510 )              ADD     RDX, [RBP+10]
( 0050AB60    48035D08 )              ADD     RBX, [RBP+08]
( 0050AB64    DEC1 )                  FADDP   ST(1), ST
( 0050AB66    48895500 )              MOV     [RBP], RDX
( 0050AB6A    C3 )                    RET/NEXT
( 43 bytes, 15 instructions )

Just to give you an idea of the "source code" after code generation,
this is how Gforth decompiles v*2:

: v*2  
  2dup f@ f@ f* fourth under+ third +
  2dup f@ f@ f* fourth under+ third + f+ ;

VFX compiles 18 Forth words into 15 instructions in this case.  For
v*64, it compiles 576 Forth words into 387 instructions.  It may or
may not be helpful for performance to load the values that it accesses
at [RBP+10] and [RBP+08] into registers, too, to reduce the usage of
load ports, which may limit the performance of this code.

>> Looking at iForth's code for VG*2, I see quite a bit of pushing and
>> popping going on, so apparently something prevents the register
>> allocator from working as well as it does on some other code.
>I don't see any "VG*2" in 
>https://www.complang.tuwien.ac.at/forth/programs/pairwise-fdot.4th ?

I meant V*2, sorry.

- 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
Technical Details
Message-ID: <2026Oct9.092016@mips.complang.tuwien.ac.at>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!2.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <2026Oct8.175513@mips.complang.tuwien.ac.at> <11a9aah$19g75$1@dont-email.me> <2026Oct9.073240@mips.complang.tuwien.ac.at> <11aa44u$9s7j$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!2.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Pairwise dot product
Date: Fri, 09 Oct 2026 07:20:16 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 87
Message-ID: <2026Oct9.092016@mips.complang.tuwien.ac.at>
References: <2026Oct8.175513@mips.complang.tuwien.ac.at> <11a9aah$19g75$1@dont-email.me> <2026Oct9.073240@mips.complang.tuwien.ac.at> <11aa44u$9s7j$1@dont-email.me>
Injection-Date: Fri, 09 Oct 2026 07:51:48 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="572498"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX196C1+Gk+gQBs2lVBi+XLSz"; posting-host="e8d347a9092f3e963a34721c3f889ca2"
Cancel-Lock: sha1:PdCcg/4ew5nvjq7DyKNZyfitpfA= sha256:qrCxA2uSJhaGAKpmwSFTUo/vOtP4aItza/84WvsUGhg=
	sha1:KsEz1kkwjeH4DkGr2r4HnE8ceoI= sha256:FDutNBFaY71E41cgOSh+eirme9CDsV9LeueW+zhXW5w=
X-newsreader: xrn 10.11
X-Received-Bytes: 5030