🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #815

Re: vector length CSR?

#815
From: Anton Ertl
Date: Thu, 19 Nov 2026 19:38
39 lines
3077 bytes
Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>On 11/19/2026 10:00 AM, Thomas Koenig wrote:
>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> schrieb:
>>> On 11/11/2026 10:53 PM, Thomas Koenig wrote:
>>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> schrieb:
>>>>     s = 0;
>>>>     for (long int i=0; i<n; i++)
>>>>       s = s + a[i];
...
>So does that mean that no parallelization of the above loop is legal? 
>Even if if wouldn't make any difference, e.g. the array entries are 
>unsigned integers?

For unsigned integers and signed integers in C, this loop can be
reassociated just fine.

For unsigned integers: The associative law holds for modulo
arithmetic, in particular unsigned addition and multiplication in C.

For signed integers: The compiler can choose what it wants to do in
case of overflow; e.g., it can choose modulo arithmetic, which is
associative.

So in both cases the code can be reassociated, and thus parallelized.

For FP addition and multiplication, the associative law does not hold,
so the compiler cannot reassociate this loop if the addition is an FP
addition.  However, gcc has a flag -ffast-math, which tells the
compiler that you do not care about bit-exact FP arithmetics.  With
this flag gcc pretends that the associative law holds even for FP +
and vectorizes this loop (with the appropriate other flags).

Can you explain why you are writing about "commutative" when what's
relevant here is the associative, not the commutative law?

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Nov19.203832@mips.complang.tuwien.ac.at>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11cpqih$acf5$1@dont-email.me> <sgu0flpndaqltpdbft40fghmi7vk78q2hs@4ax.com> <11cq2v7$dh5b$1@dont-email.me> <8jk1fl182pskj3fsmp4ju6qf420pgl0htg@4ax.com> <11csull$1ef6e$1@dont-email.me> <2026Nov9.230104@mips.complang.tuwien.ac.at> <11cvcr4$28k7g$1@dont-email.me> <11d3npt$3mmho$1@dont-email.me> <11dn936$2ebc2$1@dont-email.me> <11dndfd$2fr9j$1@dont-email.me> <11dngb5$2he51$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.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.arch
Subject: Re: vector length CSR?
Date: Thu, 19 Nov 2026 19:38:32 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 39
Message-ID: <2026Nov19.203832@mips.complang.tuwien.ac.at>
References: <11cpqih$acf5$1@dont-email.me> <sgu0flpndaqltpdbft40fghmi7vk78q2hs@4ax.com> <11cq2v7$dh5b$1@dont-email.me> <8jk1fl182pskj3fsmp4ju6qf420pgl0htg@4ax.com> <11csull$1ef6e$1@dont-email.me> <2026Nov9.230104@mips.complang.tuwien.ac.at> <11cvcr4$28k7g$1@dont-email.me> <11d3npt$3mmho$1@dont-email.me> <11dn936$2ebc2$1@dont-email.me> <11dndfd$2fr9j$1@dont-email.me> <11dngb5$2he51$1@dont-email.me>
Injection-Date: Thu, 19 Nov 2026 19:52:20 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2681145"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18kQJrdgmtDUNen1fy7Oup2"; posting-host="eb2f5bd5746d223b058ab42788bfc498"
Cancel-Lock: sha1:w+NGWCI73qQemzfvx8nl6SAma0M= sha256:tgXyuKRBHP/FHuE4hIwpQljuJFv79PPlGWq/bSqrulQ=
	sha1:/47NlbtMTR4JfMPOwGXdzzmu0tw= sha256:B6PyLTfBCGhfjGTV3mkwB+hDlsf6Xv9Mknl1Tr46t6I=
X-newsreader: xrn 10.11