Article View: comp.arch
Article #1057Re: reassociation and undefined behaviour
From: Scott Lurndal
Date: Thu, 03 Dec 2026 20:50
Date: Thu, 03 Dec 2026 20:50
33 lines
2445 bytes
2445 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes: >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 ??? If the programmer wants a zero, surely it is more efficient to to just assign zero the the variable rather than right-shifting some random 32-bit value by 32 bits.
Technical Details
Message-ID:
<eCkQS.41981$ncv4.3699@fx06.iad>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx06.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> <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>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx06.iad.POSTED!not-for-mail X-newsreader: xrn 9.03-beta-14-64bit Sender: scott@dragon.sl.home (Scott Lurndal) From: scott@slp53.sl.home (Scott Lurndal) Reply-To: slp53@pacbell.net 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> <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> Lines: 33 Message-ID: <eCkQS.41981$ncv4.3699@fx06.iad> X-Complaints-To: abuse@usenetserver.com NNTP-Posting-Date: Thu, 03 Dec 2026 20:50:18 UTC Organization: UsenetServer - www.usenetserver.com Date: Thu, 03 Dec 2026 20:50:18 GMT X-Received-Bytes: 2182