mpz_get_si: possible undefined behaviour? [Was: Micro-GMP]

Marco Bodrato bodrato at mail.dm.unipi.it
Fri Dec 7 18:53:35 UTC 2018


Ciao,

Il Mer, 5 Dicembre 2018 1:55 pm, Torbjörn Granlund ha scritto:
> Let's follow these principles:
>
> 1. We don't need to support every past and present system. E.g., we
>    do not support any 16-bit or 8-bit processors, nor do we support the
>    once popular 36-bit systems.

I don't agree :-P

I mean: it would be nice to have a library that can pass all the tests of
our suite even if we include asl.h, wouldn't it?
Well... this means, more or less, to support 8-bit, 16-bit, and also
(because it's even simpler !-) 36-bit limb size; doesn't it?

It's not a priority, I agree, but... we should move towards that direction.

In some code I recently wrote, I added some short-cuts
#if GMP_NUMB_BITS % 16 == 0
and
#if GMP_NUMB_BITS % 32 == 0
but the code is intended for any (not too small) bit size, why not?

> 2. We should avoid undefined behaviour which might be relevant only to
>    systems we support.  E.g. we might want to avoid signed overflow, or
>    conversion between negative signed and unsigned integers.

I don't agree with the word "only".

We should avoid undefined behaviour which might be relevant to systems we
support. Of course.

If we can avoid undefined behaviour also for other systems, at no cost for
the systems we support (eg. using a constant like (LONG_MIN + LONG_MAX)
where (-1) is intended for the systems we support and (0) is needed for
exotic systems that may arise)... then, why not?

Ĝis,
m

-- 
http://bodrato.it/papers/



More information about the gmp-devel mailing list