Article View: comp.arch
Article #1100Re: reassociation and undefined behaviour
From: Waldek Hebisch
Date: Sat, 05 Dec 2026 16:18
Date: Sat, 05 Dec 2026 16:18
43 lines
2902 bytes
2902 bytes
Scott Lurndal <scott@slp53.sl.home> wrote:
> 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.
Only if shift amount is constant. But except for confused
optimizers that is non-issue. What matters at hardware level
is variable amount shifts. And for variable amount shift
having shifter that is doing right thing is much better than
adding branch to handle cases producing 0.
--
Waldek Hebisch
Technical Details
Message-ID:
<11f1dgt$3r7e$1@paganini.bofh.team>Path:
mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!paganini.bofh.team!not-for-mailReferences:
<11cpqih$acf5$1@dont-email.me> <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> <eCkQS.41981$ncv4.3699@fx06.iad>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.arch
Subject: Re: reassociation and undefined behaviour
Date: Sat, 5 Dec 2026 16:18:40 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11f1dgt$3r7e$1@paganini.bofh.team>
References: <11cpqih$acf5$1@dont-email.me> <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> <eCkQS.41981$ncv4.3699@fx06.iad>
Injection-Date: Sat, 5 Dec 2026 16:18:40 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="126190"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2