v5.0.1, Mac, 32-bit: gmp_snprintf problem for (high) multi-limb integers
Max Neunhoeffer
neunhoef at mcs.st-and.ac.uk
Sun Mar 27 22:52:14 CEST 2011
Dear Torbjörn,
I am a colleague of John McDermott. Although I am technically on
holiday just now, I had a go at investigating this bug yesterday night
and I believe I found something. Please excuse this slightly terse
report, but I hope this helps you to spot the problem and I do not have
enough time right now to finish the investigation:
What I did was debugging the printing and simply comparing what happens
Linux 32bit and MacOSX 32bit. I found the following:
(1) It is not only the printing which does not work, but also
division with remainder:
gap> 10^40 mod 10^20;
returns something nonzero. Internally, this calls mpn_tdiv_qr
with the two numbers as GMP numbers.
I found this by debugging the printing and it trips over a division
with remainder by a large power of 10.
(2) At least the function "invert_limb" (aka "__gmpn_invert_limb")
behaves differently on Linux 32bit and Mac 32bit and seems to be
wrong on Mac 32bit.
(3) This function seems to be implemented in Assembler and can be
found in
gmp-5.0.1/mpn/invert_limb.asm
(4) During the compilation of GMP the following command is executed:
m4 -DOPERATION_invert_limb `test -f 'invert_limb.asm' || echo
+'./'`invert_limb.asm >tmp-invert_limb.s
So m4 is used to create the actual assembler-source-code.
This step seems to go wrong, since the 5th assembler statement
in __gmpn_invert_limb which reads
movzwl -1024+approx_tab(%eax, %eax), %eax C %eax = v0
in invert_limb.asm is correctly translated into
movzwl -1024+approx_tab(%eax, %eax), %eax
on Linux but incorrectly translated into
movzwl -1024+__gmpn_invert_limb_tab, %eax
on MacOS.
This leads to the fact that in some lookup table the lookup does no
longer work. This trips up invert_limb and division.
Note that the file invert_limb.asm says:
C Make approx_tab global to work around Apple relocation bug.
ifdef(`DARWIN',`
define(`approx_tab', MPN(invert_limb_tab))
GLOBL approx_tab')
Is this the problem?
I hope this helps,
Cheers,
Max.
On Sun, Mar 27, 2011 at 09:27:18PM +0200, Torbjorn Granlund wrote:
> John McDermott <jjm at mcs.st-and.ac.uk> writes:
>
> I now have a couple of Apple Macs available and have done some further
> testing. Please let me know if you would like ssh access to these and
> we can arrange it off list.
>
> Thanks.
>
> Somewhat more surprisingly, I have built a version of gcc 4.5.2 from
> source on each machine and then used that to compile GMP 5.0.1 and
> again the compiled short test program (see message one in this thread)
> exhibits the print problem.
>
> Very strange. This of course points to a GMP bugs. What is strange is
> that it survives such massive testing.
>
> I've added a special test for next night's round of testing to see if I
> can reproduce the problem on a more convenient platform.
>
> --
> Torbjörn
--
Max Neunhoeffer http://www-groups.mcs.st-and.ac.uk/~neunhoef/
> > > > > > > > > > > May the Source be with you! < < < < < < < < < < < <
The University of St Andrews is a registered Scottish charity: No SC013532
More information about the gmp-bugs
mailing list