Article View: comp.lang.forth
Article #49Re: Pairwise dot product
From: peter
Date: Fri, 09 Oct 2026 19:15
Date: Fri, 09 Oct 2026 19:15
78 lines
4604 bytes
4604 bytes
On Thu, 08 Oct 2026 21:37:25 GMT anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote: > peter <peter.noreply@tin.it> writes: > >I tested this on lxf64 running on a ryzen 9950x > > > >I got > > cycles instructions > >pairwise 789,294,432 3,628,952,994 > >naive 2,510,536,091 6,512,423,204 > > Nice! > > >First run with naive I got 35,476,814,233 cycles and 54,012,383,854 instr. > >I saw that you checked for F*+ . I have that as a library call, obviously > >clang does not use a fma instruction for it but instead compiles a call > >to a libray function. > > I expect that with the right flags (maybe -march=x86-64-v3 will work) > it will use an fma instruction. Because these instructions were only > added in ~2010, they are not generated normally; and because C's fma() > guarantees that rounding only happens at the end (not between the f* > and the f+), it has to do an expensive library function if there is no > fma instruction available. clang was actually generating the correct fma instruction. All the cycles were spent in calling the library function. There are 5 calls to reach the lone instruction. I need to find a more efficient setup to call external libraries. For io that was the main interest for the library this is not a problem, neither for long math functions. I will add a fma opcode to the VM. Doing a preliminary test does not show a speed increase, contrary it is a bit slower. The benefit would be in the higher precision. The results are cycles instructions fma 3,008,490,491 6,013,315,970 f* f+ 2,510,275,518 6,512,423,192 The inner loops become almost identical fma 0x428FF1 C5FB100B vmovsd xmm1, qword ptr [rbx] 0x428FF5 488B4500 mov rax, qword ptr [rbp] 0x428FF9 C5FB1010 vmovsd xmm2, qword ptr [rax] 0x428FFD C4E2F1A9D0 vfmadd213sd xmm2, xmm1, xmm0 0x429002 498B442418 mov rax, qword ptr [r12+0x18] 0x429007 48034500 add rax, qword ptr [rbp] 0x42900B 49035C2408 add rbx, qword ptr [r12+0x8] 0x429010 C5EB10C2 vmovsd xmm0, xmm2, xmm2 0x429014 48894500 mov qword ptr [rbp], rax f* f+ 0x428D01 C5FB100B vmovsd xmm1, qword ptr [rbx] 0x428D05 488B4500 mov rax, qword ptr [rbp] 0x428D09 C5FB1010 vmovsd xmm2, qword ptr [rax] 0x428D0D C5EB59D1 vmulsd xmm2, xmm2, xmm1 0x428D11 C5EB58D0 vaddsd xmm2, xmm2, xmm0 0x428D15 498B442418 mov rax, qword ptr [r12+0x18] 0x428D1A 48034500 add rax, qword ptr [rbp] 0x428D1E 49035C2408 add rbx, qword ptr [r12+0x8] 0x428D23 C5EB10C2 vmovsd xmm0, xmm2, xmm2 0x428D27 48894500 mov qword ptr [rbp], rax BR Peter > > >I would guess that lxf is limited by the use of the x87 fpus small stack > >But I need to confirm that > > For the version I used in benchmarking, I saw lots of code for the > data stack stuff, so either the FP stuff or working with ]] ... [[ > seems to throw the usually perfect code generation of lxf for > straight-line code off track. > > - anton
Technical Details
Message-ID:
<20261009211531.00000eea@tin.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<2026Oct8.175513@mips.complang.tuwien.ac.at> <20261008232336.0000698f@tin.it> <2026Oct8.233725@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!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: peter <peter.noreply@tin.it> Newsgroups: comp.lang.forth Subject: Re: Pairwise dot product Date: Fri, 9 Oct 2026 21:15:31 +0200 Organization: A noiseless patient Spider Lines: 78 Message-ID: <20261009211531.00000eea@tin.it> References: <2026Oct8.175513@mips.complang.tuwien.ac.at> <20261008232336.0000698f@tin.it> <2026Oct8.233725@mips.complang.tuwien.ac.at> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Fri, 09 Oct 2026 19:15:35 +0000 (UTC) Injection-Info: dont-email.me; logging-data="972013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+16Hs5F2eLKtfNf3fkvAWI82VcI5mh5SU="; posting-host="c1746dbc28660f977944eda05c4dde05" Cancel-Lock: sha1:XLWpTzyVsrM4odLk28qG4RALuq8= sha256:Ys7Vm/JY+ABxRiIIv17Dvs+evnxLvR+W8ciOtsIvdLI= sha1:cUpzo0XLVPsVwYaVBEJ48n0wsGQ= sha256:Io0voLY0XoyOGP5nc83zTVjtQHiaeux5mBYItcsL0qI= X-Newsreader: Claws Mail 4.4.0 (GTK 3.24.51; x86_64-w64-mingw32)