[Aldor-l] Using GMP and extending the biging protocol
Gabriel Dos Reis
gdr at integrable-solutions.net
Sat Aug 16 02:24:40 EDT 2008
On Fri, Aug 15, 2008 at 11:02 PM, Stephen Watt <watt at scl.csd.uwo.ca> wrote:
> Thanks for looking into this stuff Pippijn.
>
> The bigint macros are supposed to use the 2's complement overflows for
> the purposes of good, not evil :).
>
> That is, there are places where they are supposed to happen and we
> count on the overflows wrapping around. This is used, for example, in
> testing for carries. It allows us to use full word arithmetic from
> C.
>
> It is probably the case that you have spotted a case where this is
> going wrong -- I haven't looked into it in detail.
>
> -- Stephen
If the C integer types used are signed (as opposed to unsigned), then
the C standard defines overflow in that case as undefined behaviour.
Some compilers (including GCC recently) have been taking advantage
of that `stuck reduction' to generate codes that may perform `not as
expected in case of 2's complement'. Some public or open source
software have been reported to be broken by that (aggressive) optimization,
and it is a battle I've lost after a much long debate about where to strike the
balance -- anybody curious may look into the GCC archives for the various
arguments on both sides of the issue.
So, I would suggest to count safely on wrapped overflow only if you're
using unsigned integer type.
-- Gaby
More information about the Aldor-l
mailing list