Article View: comp.arch
Article #857Re: vector length CSR?
From: David Brown
Date: Sat, 21 Nov 2026 14:17
Date: Sat, 21 Nov 2026 14:17
49 lines
3976 bytes
3976 bytes
On 21/11/2026 15:01, Thomas Koenig wrote: > David Brown <david.brown@hesbynett.no> schrieb: >> On 20/11/2026 19:57, Thomas Koenig wrote: >>> Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb: >>>> 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. >>> >>> Not according to the C standard. >> >> Yes, according to the C standards. UB on signed integer overflow means >> the language does not say anything about what happens on overflow - it >> does not mean the compiler has to handle it specially. > > Yep, I was too short in what I wrote. Of course, the compiler can > assign any meaning to undefined behavior that it choses. What I > *did* mean to write is that a programmer cannot expect this loop > to be reassociated. > I would say that programmers can and should expect that a loop like this might be re-arranged by the compiler, for both signed and unsigned types. You rarely want to rely on an assumption of optimisation - if you /need/ the loop to be optimised in some particular way, then you typically have to use compiler-specific features (like gcc's "#pragma GCC ivdep" or "vector_size" attributes), intrinsic functions for a particular target, or perhaps C++26's "simd" features. If you really need the loop /not/ to be re-arranged, then you need to inform the compiler of that too - compiler flags, "#pragma GCC unroll 0", using volatile, etc. Without additional effort from the compiler user, a loop like this can be re-arranged using commutative and associative laws and any other information the compiler has. I would not expect the compiler to handle this differently for signed or unsigned types.
Technical Details
Message-ID:
<11ds95m$4co4$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<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> <2026Nov19.203832@mips.complang.tuwien.ac.at> <11dq56a$3f094$1@dont-email.me> <11ds0io$12f8$1@dont-email.me> <11ds88c$46jd$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.arch Subject: Re: vector length CSR? Date: Sat, 21 Nov 2026 15:17:26 +0100 Organization: A noiseless patient Spider Lines: 49 Message-ID: <11ds95m$4co4$1@dont-email.me> 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> <2026Nov19.203832@mips.complang.tuwien.ac.at> <11dq56a$3f094$1@dont-email.me> <11ds0io$12f8$1@dont-email.me> <11ds88c$46jd$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 21 Nov 2026 14:17:27 +0000 (UTC) Injection-Info: dont-email.me; logging-data="144132"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QMVrv4LNQPjr7N8MSTPpDEpQeg4domMk="; posting-host="e9cc8568760c122c84a8bb7d362e291d" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ldAcKItzYhXjXJq//uaxIXdvxIQ= sha256:L4MomlphUfmKH3Yb63SD9Dl4uvPe9yiIl8/Wx5oSoJU= sha1:FaLv5M95OjCWRlDlD9KKjE/u2+8= sha256:zflGD9TZHq4dOws2nb62RdLWpsvsa8LVLYSm5h0I1xI= Content-Language: en-GB In-Reply-To: <11ds88c$46jd$1@dont-email.me>