Article View: comp.arch
Article #1116Re: reassociation and undefined behaviour
From: Scott Lurndal
Date: Sat, 05 Dec 2026 22:15
Date: Sat, 05 Dec 2026 22:15
46 lines
3751 bytes
3751 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes: >scott@slp53.sl.home (Scott Lurndal) posted: > >> MitchAlsup <user5857@newsgrouper.org.invalid> writes: >> >David Brown <david.brown@hesbynett.no> posted: >> > >> >> On 04/12/2026 18:11, Thomas Koenig wrote: >> >> > EricP <ThatWouldBeTelling@thevillage.com> schrieb: >> >> >> On 2026-Dec-04 03:35, David Brown wrote: >> >> >>> On 03/12/2026 20:43, MitchAlsup wrote: >> >> >>> >> >> >>> So it is useful in the same way that two's complement wrapping for signed arithmetic is useful - it is absolutely absurd mathematically that you can add two positive numbers and get a negative one, there is almost certainly a bug in your program if this happens in general code, but it matches the hardware, is often harmless, and it is occasionally handy. >> >> >> >> >> >> Why is signed twos's complement wrapping mathematically absurd? >> >> > >> >> > If you add enough apples to a pile, the number of apples becomes >> >> > negative (to quote Dan Brown ;-) >> >> > >> >> >> >> I don't know who Dan Brown is (other than the author), but it is >> >> certainly the illustrative example I've used on a number of occasions. >> >> >> >> Of course if you want to have a modulo arithmetic system with signed >> >> integers of a particular size, two's complement wrapping integers are >> >> great (assuming they match the modulo you want!). But that's not what >> >> people usually want to model when they use "int" or similar types in >> >> most languages - they want a type that models mathematical integers as >> >> well as practically possible with maximally efficient implementations on >> >> their hardware. >> > >> >In most RISC ISA, 'long int' is faster than 'int' because when a unit >> >of arithmetic is performed and one cannot prove that the result fits >> >in an 'int' range then [SZ]EXTs have to be performed--or the result >> >cannot remain in a register. >> >> IME sign/zero extension can be done within the single cycle >> taken by most integer arithmetic operations - I would not expect a difference >> in instruction execution time caused by sign extension. > >But only if you fuse [SZ]ext with intOP. I'm not sure 'fuse' is the right term. the intOp logic may include the capability to sign extend, or it may be a property of the register file logic to automatically sign or zero-extend depending on the intOp.
Technical Details
Message-ID:
<920RS.1049446$jCzf.519053@fx24.iad>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx24.iad.POSTED!not-for-mailReferences:
<11cpqih$acf5$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> <11etu0b$1aih9$1@dont-email.me> <TlCQS.44884$7vt4.19168@fx07.iad> <11eus8u$1q9ee$1@dont-email.me> <11euul5$1ritd$1@dont-email.me> <1796416716-5857@newsgrouper.org> <PwHQS.53987$sI54.33877@fx48.iad> <1796434689-5857@newsgrouper.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx24.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> <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> <11etu0b$1aih9$1@dont-email.me> <TlCQS.44884$7vt4.19168@fx07.iad> <11eus8u$1q9ee$1@dont-email.me> <11euul5$1ritd$1@dont-email.me> <1796416716-5857@newsgrouper.org> <PwHQS.53987$sI54.33877@fx48.iad> <1796434689-5857@newsgrouper.org> Lines: 46 Message-ID: <920RS.1049446$jCzf.519053@fx24.iad> X-Complaints-To: abuse@usenetserver.com NNTP-Posting-Date: Sat, 05 Dec 2026 22:15:33 UTC Organization: UsenetServer - www.usenetserver.com Date: Sat, 05 Dec 2026 22:15:33 GMT X-Received-Bytes: 3450