Article View: comp.arch
Article #1120Re: reassociation and undefined behaviour
From: Josh Vanderhoof
Date: Sun, 06 Dec 2026 00:44
Date: Sun, 06 Dec 2026 00:44
32 lines
2633 bytes
2633 bytes
Michael S <already5chosen@yahoo.com> writes: > 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: >> >> >> >>> 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. Why does everything do that instead of the more useful behavior? Wouldn't it be pretty cheap to return 0 or the sign bit if any bits past bit 5 are set? Even in the 70's it doesn't seem like that'd be such a big deal.
Technical Details
Message-ID:
<ygn4icrb5le.fsf@y.z>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!fx34.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> <11f223l$3cpaq$1@dont-email.me> <20261206003301.00002080@yahoo.com>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!fx34.iad.POSTED!not-for-mail From: Josh Vanderhoof <x@y.z> Newsgroups: comp.arch Subject: Re: reassociation and undefined behaviour 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> <20261206003301.00002080@yahoo.com> User-Agent: Gnus/5.13 (Gnus v5.13) Reply-To: Josh Vanderhoof <jlv@mxsimulator.com> Message-ID: <ygn4icrb5le.fsf@y.z> Cancel-Lock: sha1:jCs42a6T7jBclVNtMBBpzz+bfrs= MIME-Version: 1.0 Content-Type: text/plain; format=flowed Lines: 32 X-Complaints-To: https://www.astraweb.com/aup NNTP-Posting-Date: Sun, 06 Dec 2026 00:41:55 UTC Date: Sat, 05 Dec 2026 19:44:29 -0500 X-Received-Bytes: 2412