From owner-freebsd-stable@FreeBSD.ORG Thu Nov 15 12:54:31 2007 Return-Path: Delivered-To: stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 83FE816A417 for ; Thu, 15 Nov 2007 12:54:31 +0000 (UTC) (envelope-from petefrench@ticketswitch.com) Received: from angel.ticketswitch.com (angel.ticketswitch.com [IPv6:2002:57e0:1d4e::1]) by mx1.freebsd.org (Postfix) with ESMTP id 4605013C503 for ; Thu, 15 Nov 2007 12:54:31 +0000 (UTC) (envelope-from petefrench@ticketswitch.com) Received: from smaug.rattatosk ([10.50.50.2]) by angel.ticketswitch.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67 (FreeBSD)) (envelope-from ) id 1IseEo-0008S5-1B; Thu, 15 Nov 2007 12:54:30 +0000 Received: from dilbert.rattatosk ([10.50.50.6] helo=dilbert.ticketswitch.com) by smaug.rattatosk with esmtp (Exim 4.67 (FreeBSD)) (envelope-from ) id 1IseEn-000Mgr-VO; Thu, 15 Nov 2007 12:54:29 +0000 Received: from petefrench by dilbert.ticketswitch.com with local (Exim 4.68 (FreeBSD)) (envelope-from ) id 1IseEn-000315-Uy; Thu, 15 Nov 2007 12:54:29 +0000 To: peterjeremy@optushome.com.au In-Reply-To: <20071115062002.GK89746@server.vk2pj.dyndns.org> Message-Id: From: Pete French Date: Thu, 15 Nov 2007 12:54:29 +0000 Cc: stable@freebsd.org Subject: Re: Float problen running i386 inary on amd64 X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2007 12:54:31 -0000 > On Fri, Nov 02, 2007 at 10:04:48PM +0000, Pete French wrote: > > int > > main(int argc, char *argv[]) > > { > > if(atof("3.2") =3D=3D atof("3.200")) > > puts("They are equal"); > > else > > puts("They are NOT equal!"); > > return 0; > > } > > Since the program as defined above does not include any prototype for > atof(), its return value is assumed to be int. The i386 code for the > comparison is therefore: Sorry, I didn't bother sticking the include lines in when I sent it to the mailing list as I assumed it would be ovious that you need to include the prototypes! In the actual tests I did I included and , so the compiler did know the return type. The result is the same, different behaviour when running the i386 binary on amd64. > Note that this is comparing the %eax returned by each atof(). Since > atof() actually returns a double in %st(0) and %eax is a scratch > register, the results are completely undefined. I just tried this with the actual code I used for the test (i.e. with the header files included) and I get something a lot longer than the assembler you posted. I don't really understand what it is doing as I don't read 386 assembler, and it's not exactly self explanatory. But the error is still there. Interestingly, if you recode like this: double x = atof("3.2"); double y = atof("3.200"); if(x == y) puts("They are equal"); else puts("They are NOT equal!"); Then the problem goes away! Glancing at the assembly code they both appear to be doing the same thing as regards the comparison. > Unfortunately, I can't explain why an i386 would be different to an amd64 > in i386 mode. me neither :-( So, this is a bug, yes ? but it is a bug in FreeBSD or not ? -pete.