mini-gmp warnings

Niels Möller nisse at lysator.liu.se
Sun Apr 26 12:31:21 UTC 2020


I'm updating the copy of mini-gmp I use in nettle to the latest version.
In Nettle, it's compiled with gcc -Wall, and I some new warnings, like

/home/nisse/hack/nettle/mini-gmp.c: In function ‘mpn_common_scan’:
/home/nisse/hack/nettle/mini-gmp.c:99:23: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
     if (GMP_LIMB_BITS > LOCAL_SHIFT_BITS)    \
                       ^
/home/nisse/hack/nettle/mini-gmp.c:112:5: note: in expansion of macro ‘gmp_clz’
     gmp_clz (__ctz_c, __ctz_x & - __ctz_x);    \
     ^~~~~~~
/home/nisse/hack/nettle/mini-gmp.c:717:3: note: in expansion of macro ‘gmp_ctz’
   gmp_ctz (cnt, limb);
   ^~~~~~~

The macro in question is

#define gmp_clz(count, x) do {						\
    mp_limb_t __clz_x = (x);						\
    unsigned __clz_c = 0;						\
    int LOCAL_SHIFT_BITS = 8;						\
    if (GMP_LIMB_BITS > LOCAL_SHIFT_BITS)				\
      for (;								\
	   (__clz_x & ((mp_limb_t) 0xff << (GMP_LIMB_BITS - 8))) == 0;	\
	   __clz_c += 8)						\
      { __clz_x <<= LOCAL_SHIFT_BITS; }					\
    for (; (__clz_x & GMP_LIMB_HIGHBIT) == 0; __clz_c++)		\
      __clz_x <<= 1;							\
    (count) = __clz_c;							\
  } while (0)

I guess it should be no harm in changing the type of LOCAL_SHIFT_BITS to
unsigned, for consistency with __clz_c? And it should probably be
renamed to have the __clz_ prefix, to match conventions for local
variables declared in macros.

Or maybe it's better and simpler to delete LOCAL_SHIFT_BITS and just use
"8" everywhere? Now it's inconsistent, and it will be somewhat messy to
replace the constant 0xff with something matching LOCAL_SHIFT_BITS,
whatever its value is.

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
to these constants via int variables? They all look a bit odd to me.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.



More information about the gmp-devel mailing list