Article View: comp.arch
Article #1117Re: reassociation and undefined behaviour
From: Michael S
Date: Sat, 05 Dec 2026 22:33
Date: Sat, 05 Dec 2026 22:33
56 lines
3352 bytes
3352 bytes
On Sat, 5 Dec 2026 23:09:58 +0100 Terje Mathisen <terje.mathisen@tmsw.no> wrote: > MitchAlsup wrote: > > anton@mips.complang.tuwien.ac.at (Anton Ertl) posted: > > > >> David Brown <david.brown@hesbynett.no> writes: > >>> On 03/12/2026 03:07, MitchAlsup wrote: > >>>> David Brown <david.brown@hesbynett.no> posted: > >>>>> In general, "(x<<n) | (x>>(32-n))" cannot be replaced with > >>>>> "undef" > >>>> > >>>> It should be replaced with:: > >>>> > >>>> ROTW Rt,Rx,Rn > >>>> > >>> > >>> Optimising compilers generally do implement such expressions with > >>> rotation instructions, when "n" is a variable. > >> > >> I looked at this in 2015, and found that clang-3.5 generates: > >> > >> mov %sil,%cl > >> rol %cl,%edi > >> > >> if it knows nothing about n, but code that produces 0 if it knows > >> that n=0. > >> > >>> There are good reasons for such shifts being UB in C. Processors > >>> are not consistent in how out-of-range shifts are handled. "x >> > >>> 32" might give 0 or it might give x. > > > > How is x a useful result ?? EVER ??? > > It is the result on all x86 cpus since the 386: > > SHR/SHL x,n > > are defined to first mask the shift count n by 31, so a shift by 32 > is exactly identical to a shift by 0. > The same on Power - for 32-bit shifts count is masked by 31, for 64-bit shifts count is masked by 63. > From other posts here, it seems that ARM also does masking but by > 255, ignoring any higher byte parts of the count. > Only 32-bit Arm. Aarch64 appears to be similar to x86 and Power. > Terje >
Technical Details
Message-ID:
<20261206003301.00002080@yahoo.com>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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> <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> <11epd07$362ph$1@dont-email.me> <1796263648-5857@newsgrouper.org> <11ergn7$6utu$1@dont-email.me> <2026Dec3.122036@mips.complang.tuwien.ac.at> <1796326998-5857@newsgrouper.org> <11f223l$3cpaq$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.arch Subject: Re: reassociation and undefined behaviour Date: Sun, 6 Dec 2026 00:33:01 +0200 Organization: A noiseless patient Spider Lines: 56 Message-ID: <20261206003301.00002080@yahoo.com> 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> <11epd07$362ph$1@dont-email.me> <1796263648-5857@newsgrouper.org> <11ergn7$6utu$1@dont-email.me> <2026Dec3.122036@mips.complang.tuwien.ac.at> <1796326998-5857@newsgrouper.org> <11f223l$3cpaq$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Sat, 05 Dec 2026 22:33:00 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3490012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GzMV3BOok6JtgF5IGwOcHvY++YP+f4qU="; posting-host="eec2e459ea6ea91de1920b0f3b02bbc3" Cancel-Lock: sha1:797FN/AShhbgtLAgBuYWuohJnhA= sha256:a0RAoIVSIs89FN6dey3DxXZxJkFLO8KoWPAUag/Jzs8= sha1:Om7Rl4eoSjti5sgAGqakyth3GAc= sha256:L9qRNifZlnaU+OI1qT1MWfw1V4FtTHSoud1p3AJWiaY= X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)