Aw: Re: Help stabilising mini-gmp
ookami1 at gmx.de
Fri Dec 2 11:18:25 UTC 2016
Gesendet: Freitag, 02. Dezember 2016 um 01:30 Uhr
Von: "Vincent Lefevre" <vincent at vinc17.net>
An: "Nelson H. F. Beebe" <beebe at math.utah.edu>
Cc: gmp-devel at gmplib.org
Betreff: Re: Help stabilising mini-gmp
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?
I wonder whether the possibly multiple encodings of 0 is the reason. We are used to
two's complement encoding of integers, but the C/C++ standard allows other (from
the today's point of view exotic) encodings like for example one's complement. And
here 0 can have the encoding all bits clear or all bits set. Now left shift FFFFFFFF
More information about the gmp-devel