Article View: comp.lang.forth
Article #38Re: Pairwise dot product
From: Anton Ertl
Date: Thu, 08 Oct 2026 22:28
Date: Thu, 08 Oct 2026 22:28
79 lines
4641 bytes
4641 bytes
Paul Rubin <no.email@nospam.invalid> writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>> With FMA instructions V* executes fewer instructions (6 per iteration
>> instead of 7), but more cycles (4 per iteration instead of 3). My
>> explanation is that the FMA instruction has 4 cycles of latency on
>> Zen4, while fadd has 3 cycles of latency.
>
>1. I wonder if FMA is faster on Intel chips.
Faster than on Zen4? Possibly (see below). Faster than FP addition
alone? Unlikely, given that FMA does everything FP addition does, and
some more.
Here are results from a Core Ultra 225 (Arrow Lake)
gforth-fast gforth-fast-v3 lxf sf64 vfx64
P-Core cycles:u
1_039_649_686 1_039_520_612 v*
5_039_839_015 5_540_303_178 4_063_130_987 5_031_130_010 2_523_537_177 st
3_479_430_650 3_478_100_387 3_478_021_063 10_679_996_938 1_743_806_482 pw
E-Core cycles:u
1_041_859_303 1_041_516_357 v*
5_041_787_120 5_041_877_231 2_052_327_326 3_535_626_061 2_033_871_643 st
2_424_544_211 2_356_400_354 1_921_908_492 8_906_205_259 1_046_854_134 pw
instructions:u
3_611_438_372 3_610_952_144 9_510_897_187 16_011_061_008 6_072_681_908 v*
11_611_688_441 11_611_192_419 9_510_888_746 16_011_051_331 6_072_663_745 st
10_157_798_459 10_141_702_338 8_267_809_187 15_963_001_737 3_821_722_537 pw
The lxf version used on this machine is 1.7-172-983.
So on these cores FMA and FP addition take only two cycles of latency,
which is very good. The E-Core beats the P-Core in cycles in
relatively many cases; and even if you take the higher clock rate of
the P-Core into account, the E-Core still beats it in time in a number
of cases.
>2. A version using AVX intrinsics would be interesting to compare.
Not sure what you mean with "AVX intrinsics" in the context of Forth;
in the x86-64-v3 version of gforth-fast, every FP instruction is an
AVX instruction. E.g., v*1 looks as follows:
<v*1> 2dup 1->2
$7FAA410750C0: mov %r8,0x0(%r13)
$7FAA410750C4: sub $0x8,%r13
$7FAA410750C8: mov 0x10(%r13),%r8
$7FAA410750CC: mov 0x8(%r13),%r9
<v*1+$8> f@ 2->1
$7FAA410750D0: vmovsd %xmm15,(%r12)
$7FAA410750D6: vmovsd (%r9),%xmm15
$7FAA410750DB: sub $0x8,%r12
<v*1+$10> f@ f* 1->1
<v*1+$18> f* 1->1
$7FAA410750DF: vmulsd (%r8),%xmm15,%xmm15
$7FAA410750E4: mov 0x8(%r13),%r8
$7FAA410750E8: add $0x8,%r13
<v*1+$20> fourth 1->2
$7FAA410750EC: mov 0x18(%r13),%r9
<v*1+$28> under+ 2->1
$7FAA410750F0: add %r9,0x8(%r13)
<v*1+$30> third 1->2
$7FAA410750F4: mov 0x10(%r13),%r9
<v*1+$38> + 2->1
$7FAA410750F8: add %r9,%r8
<v*1+$40> ;s 1->1
$7FAA410750FB: mov (%r14),%rbx
$7FAA410750FE: add $0x8,%r14
$7FAA41075102: mov (%rbx),%rax
$7FAA41075105: jmp *%rax
- 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.002856@mips.complang.tuwien.ac.at>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-mailReferences:
<2026Oct8.175513@mips.complang.tuwien.ac.at> <87ld882afn.fsf@nightsong.com>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: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.lang.forth Subject: Re: Pairwise dot product Date: Thu, 08 Oct 2026 22:28:56 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 79 Message-ID: <2026Oct9.002856@mips.complang.tuwien.ac.at> References: <2026Oct8.175513@mips.complang.tuwien.ac.at> <87ld882afn.fsf@nightsong.com> Injection-Date: Thu, 08 Oct 2026 22:49:54 +0000 (UTC) Injection-Info: dont-email.me; logging-data="257990"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pzK0XBsxGaKkWkZB4FBUz"; posting-host="4440b373708cb595d29900b8ff51a766" Cancel-Lock: sha1:qtWp1iJTGIOZqhZhfPatSKcmSwM= sha256:oR0/SHnNIk4XujOoAdkaM0l/rIBOTi98aJ3dFRUxX30= sha1:5e33A7KrIpUJ1PWPbK2K2KNmVkg= sha256:DYCcTUTYV25AQXUlqW2mn7YlxS6a4JxWMp5cyf1jPlE= X-newsreader: xrn 10.11