Help stabilising mini-gmp
Vincent Lefevre
vincent at vinc17.net
Fri Dec 2 00:30:48 UTC 2016
On 2016-12-01 16:42:39 -0700, Nelson H. F. Beebe wrote:
> Vincent Lefevre <vincent at vinc17.net> asks in response to my lengthy
> posting earlier today about where the behavior of bit-shift operations
> allows undefined behavior in C and C++:
>
> >> ...
> >> Is this true even when the shifted value is zero? For some time,
> >> I've wondered why this was also undefined for zero (in MPFR, we
> >> had code where the shift count could be out of range only for
> >> the value 0).
> >> ...
>
> No, zero shifts should be perfectly legal, because they just amount to
> a no-op, and thus a copy of source to destination. The hardware
> manuals that I checked today all permit a zero shift count: it would
> take wasteful extra chip circuitry to add a check for such a case.
I'm not talking about a zero shift count, but a shift of the value 0
with an arbitrary shift count, e.g. (uint64_t) 0 << 64. This is
undefined behavior, but I wonder why. When mapped to a hardware
instruction, does the result depend on the platform?
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-devel
mailing list