Date: Sat, 17 Nov 2007 07:35:12 +1100 From: Peter Jeremy <peterjeremy@optushome.com.au> To: Bruce Evans <brde@optusnet.com.au> Cc: stable@freebsd.org, bde@freebsd.org, Pete French <petefrench@ticketswitch.com> Subject: Re: Float problen running i386 inary on amd64 Message-ID: <20071116203512.GD20992@server.vk2pj.dyndns.org> In-Reply-To: <20071117025943.P64582@delplex.bde.org> References: <20071115062002.GK89746@server.vk2pj.dyndns.org> <E1IseEn-000315-Uy@dilbert.ticketswitch.com> <20071115184615.GL20992@server.vk2pj.dyndns.org> <20071117025943.P64582@delplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--5I6of5zJg18YgZEa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 17, 2007 at 04:53:22AM +1100, Bruce Evans wrote: >Behaviour like this should be expected on i386 but not on amd64. It >gives the well-known property of the sin() function, that sin(x) !=3D sin(= x) >for almost all x (!). It happens because expressions _may_ be evaluated >in extra precision (this is perfectly standard), so identical expressions= =20 >may sometimes be evaluated in different precisions even, or especially, >if they are on the same line. Thank you for your detailed analysis. Hwever, I believe you missed the critical point (I may have removed too much reference to the actual problem that Pete French saw): I can take a program that was statically compiled on FreeBSD/i386, run it in legacy (i386) mode on FreeBSD-6.3/amd64 and get different results. Another (admittedly contrived) example: jashank% uname -a = =20 FreeBSD jashank.vk2pj.dyndns.org 6.1-STABLE FreeBSD 6.1-STABLE #15: Wed Aug= 2 18:35:57 EST 2006 root@jashank.vk2pj.dyndns.org:/usr/obj/usr/src/sy= s/jashank i386 jashank% cat y.c #include <stdio.h> double one =3D 1.0; double three =3D 3.0; double third =3D 1.0/3.0; int main(int argc, char **argv) { if (one/three =3D=3D third) puts("Equal"); else puts("NOT Equal"); return (0); } jashank% cc -O2 -fno-strict-aliasing -pipe -march=3Dathlon y.c -static -o= y jashank% ./y Equal jashank% /sbin/sha256 y SHA256 (y) =3D d44fe8c4c4b4beab6125ba603f2a34fa4d0280ff04d697e22594debf9efc= 9a1a jashank%=20 turion% uname -a FreeBSD turion.vk2pj.dyndns.org 6.2-STABLE FreeBSD 6.2-STABLE #30: Tue Jul = 31 20:29:49 EST 2007 root@turion.vk2pj.dyndns.org:/usr/obj/usr/src/sys/= turion amd64 turion% scp -p jashank:y . =20 y 100% 146KB 145.9KB/s 00:00= =20 turion% /sbin/sha256 y SHA256 (y) =3D d44fe8c4c4b4beab6125ba603f2a34fa4d0280ff04d697e22594debf9efc= 9a1a turion% ./y NOT Equal turion%=20 This is identical code being executed in supposedly equivalent environments giving different results. I believe the fix is to initialise the FPU using __INITIAL_NPXCW__ in ia32_setregs(), though I'm not sure how difficult this is in reality. --=20 Peter Jeremy Please excuse any delays as the result of my ISP's inability to implement an MTA that is either RFC2821-compliant or matches their claimed behaviour. --5I6of5zJg18YgZEa Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFHPf7//opHv/APuIcRAjUpAKDD7ALpNxKehry9KyiIscoNUPcTPACfTKnL Y+cceitfaXLAOg/jSS53/8M= =0/6f -----END PGP SIGNATURE----- --5I6of5zJg18YgZEa--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071116203512.GD20992>