Article View: comp.arch
Article #1040Re: reassociation and undefined behaviour
From: Anton Ertl
Date: Thu, 03 Dec 2026 07:20
Date: Thu, 03 Dec 2026 07:20
34 lines
2891 bytes
2891 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>Older ISA would avoid UB by defining 2× MUL and 2× DIV to avoid Overflow
>
> MULD {Rt1,Rt2},Ra,Rb
Yes, widening multiplication does not overflow. Many ISAs do widening
multiplication by having instructions that produce the upper word of a
widening multiplication in addition to the ordinary modulo-arithmentic
multiplication. RISC-V has MULH (signed), MULHU (unsigned), and
MULHSU (signed*unsigned).
> DIV {Rrem,Rquo},{Rt1,Rt2},Rdiv
Narrowing division has several ways to overflow or have other results
that do not fit "divide and round according to symmetric/truncated,
floored, or Euclidean regimes":
1) Division by 0.
2) Signed division of the minimum single-word number by -1 (not
representable). This hits even without narrowing division.
3) Division of a double-word by a single-word where the result is too
big for a single word (of the intended type). For unsigned
division, this happens if the high word of the dividend >= the
divisor.
Despite 3, narrowing division is a useful component of a number of
computations, and it's a pity that many recent ISAs do not have it.
- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID:
<2026Dec3.082040@mips.complang.tuwien.ac.at>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!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!.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>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!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!.POSTED!not-for-mail From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.arch Subject: Re: reassociation and undefined behaviour Date: Thu, 03 Dec 2026 07:20:40 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 34 Message-ID: <2026Dec3.082040@mips.complang.tuwien.ac.at> 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> Injection-Date: Thu, 03 Dec 2026 07:36:31 +0000 (UTC) Injection-Info: dont-email.me; logging-data="39414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18My71PxEY8c+rynK7scwdf"; posting-host="b318e488349409aaa87abf1f338dcb0c" Cancel-Lock: sha1:yKRhAXe4lz0tb5JdJ5VffWgJ7GM= sha256:XDBtc4yURXCaKSHbIFpSpgIhpRr+7zQlSFOrEtqAzIA= sha1:8YYzqqKBc3ydhzdbgzMxjlNSDXY= sha256:iS8yU9Zg+LIK3F5NpVHWhdPQ7vTdKCGrGlEPPEsUePY= X-newsreader: xrn 10.11