Article View: comp.arch
Article #1029Re: reassociation and undefined behaviour
From: EricP
Date: Wed, 02 Dec 2026 19:18
Date: Wed, 02 Dec 2026 19:18
37 lines
2577 bytes
2577 bytes
On 2026-Dec-02 07:24, Anton Ertl wrote: > David Brown <david.brown@hesbynett.no> writes: >> On 01/12/2026 20:01, Stefan Monnier wrote: >>> Is it? AFAIK, in C >>> >>> (-2 + INTMAX) + 1 >>> >>> is not the same as >>> >>> -2 + (INTMAX + 1) >>> >>> because the second two bumps into a UB while the first doesn't. > ... >> If the generated code uses some kind of "trap on overflow" addition >> instruction, then the compiler may not change the first expression into >> the second. But if the compiler is generating two's complement wrapping >> instructions, it certainly can do so. > > Two other options are: > > * saturating arithmetics, used for signal processing. It's not > associative. Only if one requires bit-wise identical results to a benchmark. Some phone voice codecs specify a saturating arithmetic algorithm and require bit-wise identical results to their test benchmarks. In that case, yes, it cannot reassociate because all codecs must always clip the signal the exact same way. However other codecs, say in a DVD player, are not so restricted. They use saturating arithmetic because having a signal overflow and wrap around is a much more jarring noise than a clip, which would only inject some high frequency harmonics. In this case reassociation and other optimizations might allowed you to optimize the codec and maybe use a lower performance (cheaper) DSP.
Technical Details
Message-ID:
<va_PS.39762$eQ94.10531@fx40.iad>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx40.iad.POSTED!not-for-mailReferences:
<11cpqih$acf5$1@dont-email.me> <86o6b6kaqf.fsf@linuxsc.com> <11ejr5e$nk8$1@reader2.panix.com> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me> <jwvbj74bzm4.fsf-monnier+comp.arch@gnu.org> <11eolqn$2peg5$1@dont-email.me> <2026Dec2.132411@mips.complang.tuwien.ac.at>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx40.iad.POSTED!not-for-mail MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: reassociation and undefined behaviour Newsgroups: comp.arch References: <11cpqih$acf5$1@dont-email.me> <86o6b6kaqf.fsf@linuxsc.com> <11ejr5e$nk8$1@reader2.panix.com> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me> <jwvbj74bzm4.fsf-monnier+comp.arch@gnu.org> <11eolqn$2peg5$1@dont-email.me> <2026Dec2.132411@mips.complang.tuwien.ac.at> Content-Language: en-CA From: EricP <ThatWouldBeTelling@thevillage.com> In-Reply-To: <2026Dec2.132411@mips.complang.tuwien.ac.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 37 Message-ID: <va_PS.39762$eQ94.10531@fx40.iad> X-Complaints-To: abuse@UsenetServer.com NNTP-Posting-Date: Wed, 02 Dec 2026 19:18:51 UTC Date: Wed, 2 Dec 2026 14:18:47 -0500 X-Received-Bytes: 2356