mpn_rshift / mpn_lshift bug on m68000
Patrick Pelissier
Patrick.Pelissier at loria.fr
Thu Oct 16 18:28:07 CEST 2003
Hello,
mpn_rshift / mpn_lshift bug are buggy (in my opinion) for the mc68000:
They are defined as:
mp_limb_t mpn_rshift (mp_limb_t *rp, const mp_limb_t *sp, mp_size_t n,
unsigned int count)
ie count parameter is a int.
It is read in the assembly file as a long:
C Copy the arguments to registers.
movel M(sp,28), res_ptr
movel M(sp,32), s_ptr
movel M(sp,36), s_size
movel M(sp,40), cnt
For mc68000, in most case, int = 16 bits, and long = 32 bits.
So the assembly function read a random value.
And as a consequence, most GMP functions are buggy...
But for mc68020, in most case, int = 32 bits, and long = 32 bits...
But you can change this with some compiler options to redefine at
compile time the size of a int (-mlong or -mshort for example)...
The best way to fix this is, in my opinion, to never use type 'int' for
a library. But it is a lot of work...
So I am sure you will find the best solution.
Sincerely,
Patrick Pelissier
PS: Another bug is that you define in gmp-impl.h:
#if defined (__mc68000__) || defined (__mc68020__) || defined (__m68k__)
|| defined(mc68020)
#define _GMP_IEEE_FLOATS 1
but mc68000 doesn't have native Floating Point Unit, so floats could
be implement by software library, which could be not in IEEE format.
Maybe it would be better to detect the format in configure?
More information about the gmp-bugs
mailing list