Date: Tue, 9 Mar 2010 06:03:01 +1100 From: Peter Jeremy <peterjeremy@acm.org> To: freebsd-sparc64@freebsd.org Cc: Marius Strobl <marius@alchemy.franken.de> Subject: Re: gcc code generation problems Message-ID: <20100308190301.GA69938@server.vk2pj.dyndns.org> In-Reply-To: <20100228192329.GA68252@server.vk2pj.dyndns.org> References: <20100228192329.GA68252@server.vk2pj.dyndns.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2010-Mar-01 06:23:30 +1100, Peter Jeremy <peterjeremy@acm.org> wrote: >The correct answer is '53', but if optimisation is enabled, I'm >getting '51' instead. Disabling the printf() and/or using >-fno-strict-aliasing has no effect. > >$ cc -DXXX -O tryfp.c; ./a.out >a 4503599627370495 !=3D 0 >51 >$ cc -DXXX -O2 tryfp.c; ./a.out >a 4503599627370495 !=3D 0 >51 >$ cc -DXXX tryfp.c; ./a.out >a 18014398509481983 !=3D 18014398509481984 >53 >$=20 I've done a bit more investigating and come to the conclusion that the FP emulation code for fxtod is trashing %f12. The problem does not exist on OpenSolaris. On FreeBSD, gcc expands a double to unsigned long cast to: if (d >=3D (double)(1UL << 63)) { ul =3D (1UL << 63) ^ (long)(d - (double)(1UL << 63)); } else { ul =3D (long)d; } In the sample code, gcc calculates (double)(1UL << 63) at the top of the function and stores it in %f12. Somehow, this register turns into 0 on the 51st iteration, though nothing updates it. If I pick a different unused register (I've tried %f16, %f24 and %f32) then the code works. The "UltraSPARC IIIi Processor User's Manual", indicates that fxtod will trap for operands >=3D 2^51 (fdtox will trap for operands >=3D 2^53 and is therefore executed in hardware) which seems to point the finger at the FP emulation code in the userland trap handler. I am still looking into the emulation code. --=20 Peter Jeremy --PEIAKu/WMn1b1Hv9 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAkuVSeUACgkQ/opHv/APuIffMACeLnK2q2l290bierARvhBP3wwG GEsAmgKDzFq4KiOknO6wfxf9cYuCLi+x =T/rq -----END PGP SIGNATURE----- --PEIAKu/WMn1b1Hv9--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100308190301.GA69938>