Article View: comp.lang.forth
Article #56Re: Pairwise dot product
From: marcel hendrix
Date: Sat, 10 Oct 2026 13:42
Date: Sat, 10 Oct 2026 13:42
84 lines
4239 bytes
4239 bytes
On 10/9/2026 12:37 PM, Anton Ertl wrote: > marcel hendrix <mhx@iae.nl> writes: >> Strange. I changed fourth and third to what I suppose is worse code, but >> \ V* : 2,598,357,958 clock ticks >> \ naive-V* : 2,596,436,412 clock ticks >> \ pairwise-V* : 2,286,386,056 clock ticks >> >> Now pairwise-V* wins. >> >> fourth and third became: >> >> : fourth ( a b c d -- a b c d a ) >S >S OVER S> S> ROT ; >> : third ( a b c -- a b c a ) >S OVER S> SWAP ; >> >> ... which looks bad, but which generates >> >> FORTH> ' v*2 idis >> $01344740 : v*2 >> $0134474A pop rbx >> $0134474B pop rdi >> $0134474C fld [rbx] qword >> $0134474E fld [rdi] qword >> $01344750 fmulp ST(1), ST >> $01344752 pop rax >> $01344753 pop rdx >> $01344754 fld [rbx rax*1] qword >> $01344757 fld [rdx rdi*1] qword >> $0134475A fmulp ST(1), ST >> $0134475C faddp ST(1), ST >> $0134475E fpush, >> $01344768 push rdx >> $01344769 push rax >> $0134476A lea rdi, [rdi rdx*2] qword >> $0134476E push rdi >> $0134476F lea rbx, [rbx rax*2] qword >> $01344773 push rbx >> $01344774 ; [..] I tried it specialized to a stride of (fixed) 1, which is the stride I normally need. There is both good and bad news: FORTH> ' v*2 idis $013446C0 : v*2 $013446CA pop rbx $013446CB pop rdi $013446CC fld [rdi] qword $013446CE fld [rbx] qword $013446D0 fmulp ST(1), ST $013446D2 fld [rdi 8 +] qword $013446D5 fld [rbx 8 +] qword $013446D8 fmulp ST(1), ST $013446DA faddp ST(1), ST $013446DC fpush, $013446E6 lea rdi, [rdi #16 +] qword $013446EA push rdi $013446EB lea rbx, [rbx #16 +] qword $013446EF push rbx $013446F0 ; Somewhat nicer code. FORTH> BENCH2 \ V* : 2,626,824,105 clock ticks \ naive-V* : 2,616,912,602 clock ticks \ pairwise-V* : 2,275,658,158 clock ticks ok ( As V* and naive-V* should give the same result, there is about 0.5% of clock jitter going on. I did let the caches warm up for a few seconds now. ) Compared to the previous results, with variable stride, >> \ V* : 2,598,357,958 clock ticks >> \ naive-V* : 2,596,436,412 clock ticks >> \ pairwise-V* : 2,286,386,056 clock ticks It appears the V* code is about 1% slower (!) but pair-wise-V* has become 1% faster. Decreasing the stack pressure does not help, the pain is somewhere else. It will be interesting to test this on the next generation of CPUs. -marcel
Technical Details
Message-ID:
<11adfbu$1dlto$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-mailReferences:
<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> <2026Oct9.092016@mips.complang.tuwien.ac.at> <11aa9kv$9va2$1@dont-email.me> <2026Oct9.123752@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: Sat, 10 Oct 2026 15:42:19 +0200 Organization: A noiseless patient Spider Lines: 84 Message-ID: <11adfbu$1dlto$1@dont-email.me> 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> <2026Oct9.092016@mips.complang.tuwien.ac.at> <11aa9kv$9va2$1@dont-email.me> <2026Oct9.123752@mips.complang.tuwien.ac.at> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 10 Oct 2026 13:42:22 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1497016"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JBl4jM2diwW8OP914CzBime2y/ERZJtY="; posting-host="28a78ccd61dc650a84c5b0a4b743199a" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:l5f1YumO+y/45Gf1IFtwYfSmx/M= sha256:/HGkhPynK9/LNBJV1ARYcSkEcMRNdiGVUSVmetG1cIU= sha1:x+LtisXum/6UxhTrUnJg5EzMke4= sha256:RCi48HQniFxd9VfAxsZMLlVMXYQPKkAYJztstUOVTaU= Content-Language: en-US In-Reply-To: <2026Oct9.123752@mips.complang.tuwien.ac.at>