From owner-freebsd-current@FreeBSD.ORG Wed Apr 4 14:45:29 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18AA01065670 for ; Wed, 4 Apr 2012 14:45:29 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from nm2-vm0.bullet.mail.sp2.yahoo.com (nm2-vm0.bullet.mail.sp2.yahoo.com [98.139.91.248]) by mx1.freebsd.org (Postfix) with SMTP id E42968FC14 for ; Wed, 4 Apr 2012 14:45:28 +0000 (UTC) Received: from [98.139.91.69] by nm2.bullet.mail.sp2.yahoo.com with NNFMP; 04 Apr 2012 14:45:28 -0000 Received: from [208.71.42.207] by tm9.bullet.mail.sp2.yahoo.com with NNFMP; 04 Apr 2012 14:45:28 -0000 Received: from [127.0.0.1] by smtp218.mail.gq1.yahoo.com with NNFMP; 04 Apr 2012 14:45:28 -0000 X-Yahoo-Newman-Id: 531220.49922.bm@smtp218.mail.gq1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 6xnD3cQVM1k1j0.JKiK9gj6dSc9KeI2GPJxGq.qcJ6nl0Fo ifqQGvsKoz90r.o_OQClv_PVPLfwdF437qxuyzz.m_R9siyw_vJNOoHQbhYX DD2ZOuMSkZgpw.UOTA6GDJuPM.Hd4uZ01RMrJMcMVh2no3.ytd2szh8iomPS aSFQkBE7aRf60H0bW8kAOpcLAFlLZjzmbFouvybGczcPIz_ZHGKC2egc44vk uzWFo6BgQIp0y.Xt5cIQ.44f2eLHiyJMSH2Fp2ssItVUTp5dc9e7_UX2Hfh. Tr_9Npz1F77fRJrxp7hjqmSRT.V.ycp0j8I.mY3K7yWpH1pkpYMgozlO9plj YLkRNQ4WLrZ0n9lnUuBz39XN.BtkBCujdNWfsOxiCKRgzx0QMEC5vEEukzjN C1Mb.QZR9HIXWGZ4Jo2hEo8EfZZAVo22C3ZS1Qfixn9yqGcuRrsTB1UyiQVj q_WtghmpSi8ny4bZJXRuSyq8_ODROvy9clGYEevzekG7jf1zBq.p.MPfs9oi PJPpFulrffTklNd7VbfDFlNI3vM3ZVdNneNCAzN_iSYyerSdjf.eagtdCOal TOwINYvUTgHWq53sxMPadsaFOWeOMF1mpfx11kU2rgdbxgwRJmlUEEg-- X-Yahoo-SMTP: xcjD0guswBAZaPPIbxpWwLcp9Unf Received: from [192.168.10.106] (pfg@200.118.157.7 with plain) by smtp218.mail.gq1.yahoo.com with SMTP; 04 Apr 2012 07:45:28 -0700 PDT Message-ID: <4F7C5E85.5090801@FreeBSD.org> Date: Wed, 04 Apr 2012 09:45:25 -0500 From: Pedro Giffuni User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:10.0.2) Gecko/20120226 Thunderbird/10.0.2 MIME-Version: 1.0 To: Andrey Simonenko References: <20120403112111.GA39616@pm513-1.comsys.ntu-kpi.kiev.ua> <20120403134300.GA98102@troutmask.apl.washington.edu> <20120404092923.GA1087@pm513-1.comsys.ntu-kpi.kiev.ua> In-Reply-To: <20120404092923.GA1087@pm513-1.comsys.ntu-kpi.kiev.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org, Steve Kargl Subject: Re: -ffast-math in Ports and wrong generated code X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2012 14:45:29 -0000 On 04/04/12 04:29, Andrey Simonenko wrote: > On Tue, Apr 03, 2012 at 06:43:00AM -0700, Steve Kargl wrote: >> On Tue, Apr 03, 2012 at 02:21:11PM +0300, Andrey Simonenko wrote: >>> I use one port from the Ports Collection, that works with FP. Having >>> reinstalled it (its version was not changed) I noticed that it started >>> to work incorrectly. After debugging and disassembling its code I found >>> out that the -ffast-math option used for building was the result of >>> wrongly generated code (I did not specify this option in /etc/make.conf). >>> >>> At least finite() function call was eliminated from the result Assembler >>> code when -ffast-math option is used, tested on 9.0-STABLE and 10.0-CURRENT. >>> >>> Example test source code and generated code under 9.0-STABLE on amd64 >>> by gcc from the base system: >>> >>> ----------------------------- >>> #include >>> #include >>> >>> void >>> check_finite(double x) >>> { >>> printf("%d\n", finite(x)); >>> } >>> ----------------------------- >>> >>> % gcc -Wall -O2 -S finite.c >>> ----------------------------- >>> check_finite: >>> .LFB3: >>> subq $8, %rsp >>> .LCFI0: >>> call finite <-- call to finite() >>> movl $.LC0, %edi >>> movl %eax, %esi >>> addq $8, %rsp >>> xorl %eax, %eax >>> jmp printf >>> .LFE3: >>> .size check_finite, .-check_finite >>> ----------------------------- >>> >>> % gcc -Wall -O2 -ffast-math -S finite.c >>> ----------------------------- >>> check_finite: >>> .LFB3: >>> xorl %esi, %esi <-- fake result from finite() >>> movl $.LC0, %edi >>> xorl %eax, %eax >>> jmp printf >>> .LFE3: >>> .size check_finite, .-check_finite >>> ----------------------------- >>> >>> Can somebody comment this? >> Read the man page for gcc. With --fast-math, >> gcc assumes that the result of any FP operation >> is finite. So, the function call to finite() >> is eliminated as it is always true. > Looks like that I was misunderstood. I did not ask why finite() was > eliminated, I asked why fake result from finite() is wrong. Obviously > that -ffast-math can optimize FP arithmetics and as a result some functions > can be eliminated. The problem is not respecting IEEE specifications for > FP, the problem is wrongly generated code when -ffast-math is used. > > Actually there is a bug in GCC used in the base system. There was made > a change to builtins.c from gcc in revision 1.12 [1] and as a result gcc > started to eliminate finite() function calls with -ffinite-math-only. > > ... > > After this change the corresponding Assembler code for my test file is: > > % gcc -Wall -O2 -ffast-math -S finite.c > ----------------------------- > check_finite: > .LFB3: > movl $1, %esi <-- fake result from finite() > movl $.LC0, %edi > xorl %eax, %eax > jmp printf > .LFE3: > .size check_finite, .-check_finite > ----------------------------- > > What do you think? If there is no objections, I'll create PR. > > [1] http://www.freebsd.org/cgi/cvsweb.cgi/src/contrib/gcc/builtins.c.diff?r1=1.11;r2=1.12 > _______________________________________________ The SVN commit http://svnweb.freebsd.org/base?view=revision&revision=228756 will point you to this: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28796 and we are keeping consistency with both upstream and Apple's gcc. Which is the affected port again? It should be fixed there or else the problem will continue with future compilers. Pedro.