mini-gmp warnings

Marco Bodrato bodrato at mail.dm.unipi.it
Sun Apr 26 13:36:05 UTC 2020


Ciao,

Il 2020-04-26 15:11 nisse at lysator.liu.se ha scritto:
> nisse at lysator.liu.se (Niels Möller) writes:
>> There are a couple of other uses of LOCAL_SHIFT_BITS,
>> LOCAL_GMP_LIMB_BITS, LOCAL_CHAR_BIT, added as part of the support for
>> testing with small limb sizes. Is it for some reason important to 
>> refer

> Now I've tried changing it, and it seems to also be a hack to avoid
> warnings?

Exactly.

> In this macro,
> 
> #define gmp_umul_ppmm(w1, w0, u, v)					\
>   do {									\
>     int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;				\
>     if (sizeof(unsigned int) * CHAR_BIT >= 2 * GMP_LIMB_BITS)		\
>       {									\
> 	unsigned int __ww = (unsigned int) (u) * (v);			\
> 	w0 = (mp_limb_t) __ww;						\
> 	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\
>       }									\
> 
> if I change the shift to
> 
> 	w1 = (mp_limb_t) (__ww >> GMP_LIMB_BITS);			\

Yes, and even more warning are triggered if mp_limb_t is unsigned 
char...

The idea of the hack is: if the compiler is not optimising, a 
non-constant shift is compiled; if the compiler optimises, a "variable" 
with a non-changing value should be removed, and the branch should be 
totally skipped.

I agree with your first proposal: use unsigned. It should be good even 
with -O0.

Ĝis,
m


More information about the gmp-devel mailing list