From owner-freebsd-current@FreeBSD.ORG Tue Apr 3 13:43:30 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 771791065679 for ; Tue, 3 Apr 2012 13:43:30 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by mx1.freebsd.org (Postfix) with ESMTP id 353938FC1F for ; Tue, 3 Apr 2012 13:43:30 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.5/8.14.5) with ESMTP id q33Dh07M098112; Tue, 3 Apr 2012 06:43:00 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.5/8.14.5/Submit) id q33Dh0ux098111; Tue, 3 Apr 2012 06:43:00 -0700 (PDT) (envelope-from sgk) Date: Tue, 3 Apr 2012 06:43:00 -0700 From: Steve Kargl To: Andrey Simonenko Message-ID: <20120403134300.GA98102@troutmask.apl.washington.edu> References: <20120403112111.GA39616@pm513-1.comsys.ntu-kpi.kiev.ua> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120403112111.GA39616@pm513-1.comsys.ntu-kpi.kiev.ua> User-Agent: Mutt/1.4.2.3i Cc: freebsd-current@freebsd.org 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: Tue, 03 Apr 2012 13:43:30 -0000 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. -- Steve