🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #1052

Re: reassociation and undefined behaviour

#1052
From: MitchAlsup
Date: Thu, 03 Dec 2026 19:43
40 lines
2603 bytes
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 C specified that the result is 0 or x, then the result of the
> expression above for n=0 would be x (because (x|x)==x and (x|0)==x).
> 
> So I think there is a good reason to specify that x>>32 is 0 or x, but
> not a good reason to make it undefined behaviour.

I, personally, do not care that C makes this UB.
What I do care about is that no ISA should allow (x>>32) == x when
x is not 0. It is arithmetically unsound.
--------------------
> - anton
Technical Details
Message-ID: <1796326998-5857@newsgrouper.org>
Path: mbox-mo1.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!newsgrouper.org!.POSTED!not-for-mail
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>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.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!newsgrouper.org!.POSTED!not-for-mail
From: MitchAlsup <user5857@newsgrouper.org.invalid>
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>
Date: Thu, 03 Dec 2026 19:43:18 GMT
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <1796326998-5857@newsgrouper.org>
Injection-Info: newsgrouper.org; mail-complaints-to="newsgrouper@yahoo.com"; posting-account=user5857
Injection-Date: Thu, 03 Dec 2026 19:43:18 GMT
User-Agent: Newsgrouper/0.9.0